tone-stream 1.4.0 → 1.4.3
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/dtmf_to_file.js +52 -0
- package/package.json +3 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { ToneStream, utils } = require('../index.js')
|
|
2
|
+
const Speaker = require('speaker')
|
|
3
|
+
const wav = require('wav')
|
|
4
|
+
|
|
5
|
+
function usage() {
|
|
6
|
+
console.log(`
|
|
7
|
+
Required parameters: 'dtmf_sequence' output_file sample_rate bit_depth, channels
|
|
8
|
+
Ex: '1234' digits.wav 16000 16 1
|
|
9
|
+
`)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
if(process.argv.length != 7) {
|
|
14
|
+
usage()
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const dtmfSequence = process.argv[2]
|
|
19
|
+
const outputFile = process.argv[3]
|
|
20
|
+
const sampleRate = parseInt(process.argv[4])
|
|
21
|
+
const bitDepth = parseInt(process.argv[5])
|
|
22
|
+
const channels = parseInt(process.argv[6])
|
|
23
|
+
|
|
24
|
+
const format = {
|
|
25
|
+
sampleRate,
|
|
26
|
+
bitDepth,
|
|
27
|
+
channels,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log("format:", format)
|
|
31
|
+
|
|
32
|
+
const tones = utils.gen_dtmf_tones(dtmfSequence, 100, 100, sampleRate)
|
|
33
|
+
|
|
34
|
+
console.log("tones:", tones)
|
|
35
|
+
|
|
36
|
+
const fileWriter = new wav.FileWriter(outputFile, format)
|
|
37
|
+
|
|
38
|
+
const ts = new ToneStream(format)
|
|
39
|
+
|
|
40
|
+
const speaker = new Speaker(format)
|
|
41
|
+
|
|
42
|
+
ts.pipe(speaker)
|
|
43
|
+
ts.pipe(fileWriter)
|
|
44
|
+
|
|
45
|
+
ts.concat(tones)
|
|
46
|
+
|
|
47
|
+
ts.on('empty', () => {
|
|
48
|
+
console.log('end_of_audio')
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
fileWriter.end()
|
|
51
|
+
}, 1000)
|
|
52
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tone-stream",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "A simple audio tone stream library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"morse-node": "^0.1.1",
|
|
30
30
|
"note-to-frequency": "^1.4.1",
|
|
31
|
-
"spec-read-stream": "^1.2.0"
|
|
31
|
+
"spec-read-stream": "^1.2.0",
|
|
32
|
+
"wav": "^1.0.2"
|
|
32
33
|
}
|
|
33
34
|
}
|