tone-stream 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/detect_tones.js +18 -41
- package/examples/dtmf_to_file.js +4 -1
- package/package.json +2 -2
package/examples/detect_tones.js
CHANGED
|
@@ -1,51 +1,28 @@
|
|
|
1
1
|
const { ToneStream } = require('../index.js')
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const {PassThrough} = require('stream')
|
|
5
|
-
|
|
6
|
-
const sampleRate = 8000
|
|
2
|
+
const DtmfDetectionStream = require('dtmf-detection-stream')
|
|
7
3
|
|
|
8
4
|
const format = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
sampleRate: 8000,
|
|
6
|
+
bitDepth: 16,
|
|
7
|
+
channels: 1,
|
|
12
8
|
}
|
|
13
9
|
|
|
14
10
|
const ts = new ToneStream(format)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
ts.concat(notes)
|
|
29
|
-
|
|
30
|
-
var detector = goertzel([697, 770, 852, 941, 1209, 1336, 1477, 1633], {
|
|
31
|
-
sampleRate: sampleRate,
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
// adding PassThrough stream to check data in the pipe
|
|
35
|
-
const pt = new PassThrough()
|
|
36
|
-
|
|
37
|
-
pt.on('data', data => {
|
|
38
|
-
console.log(data.length, data)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
ts.pipe(pt)
|
|
42
|
-
pt.pipe(detector)
|
|
43
|
-
|
|
44
|
-
detector.on('toneStart', function (tones) {
|
|
45
|
-
console.log('start', tones)
|
|
11
|
+
ts.add([800, 's']) // silence
|
|
12
|
+
ts.add([800, 'DTMF:1'])
|
|
13
|
+
ts.add([800, 's']) // silence
|
|
14
|
+
ts.add([800, 'DTMF:2'])
|
|
15
|
+
ts.add([800, 's']) // silence
|
|
16
|
+
ts.add([800, 'DTMF:3'])
|
|
17
|
+
ts.add([800, 's']) // silence
|
|
18
|
+
|
|
19
|
+
const dds = new DtmfDetectionStream(format)
|
|
20
|
+
|
|
21
|
+
dds.on('dtmf', data => {
|
|
22
|
+
console.log('Got', data)
|
|
46
23
|
})
|
|
47
24
|
|
|
48
|
-
|
|
49
|
-
|
|
25
|
+
ts.on('data', data => {
|
|
26
|
+
dds.write(data)
|
|
50
27
|
})
|
|
51
28
|
|
package/examples/dtmf_to_file.js
CHANGED
|
@@ -5,7 +5,9 @@ const wav = require('wav')
|
|
|
5
5
|
function usage() {
|
|
6
6
|
console.log(`
|
|
7
7
|
Required parameters: 'dtmf_sequence' output_file sample_rate bit_depth, channels
|
|
8
|
-
|
|
8
|
+
'1234' digits.1234.8000hz.wav 8000 16 1
|
|
9
|
+
'1234' digits.1234.16000hz.wav 16000 16 1
|
|
10
|
+
'1234' digits.1234.32000hz.wav 32000 32 1
|
|
9
11
|
`)
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -43,6 +45,7 @@ ts.pipe(speaker)
|
|
|
43
45
|
ts.pipe(fileWriter)
|
|
44
46
|
|
|
45
47
|
ts.concat(tones)
|
|
48
|
+
ts.add([ sampleRate, 's' ])
|
|
46
49
|
|
|
47
50
|
ts.on('empty', () => {
|
|
48
51
|
console.log('end_of_audio')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tone-stream",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A simple audio tone stream library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"author": "MayamaTakeshi",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"goertzel-stream": "git+https://github.com/MayamaTakeshi/goertzel-stream.git",
|
|
25
24
|
"lodash": "^4.17.21",
|
|
26
25
|
"speaker": "^0.5.1"
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
28
|
+
"dtmf-detection-stream": "^1.10.0",
|
|
29
29
|
"morse-node": "^0.1.1",
|
|
30
30
|
"note-to-frequency": "^1.4.1",
|
|
31
31
|
"spec-read-stream": "^1.2.0",
|