tone-stream 1.11.0 → 1.11.2
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/README.md +38 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,23 +28,32 @@ const { ToneStream } = require('tone-stream')
|
|
|
28
28
|
|
|
29
29
|
const Speaker = require('speaker')
|
|
30
30
|
|
|
31
|
+
const sampleRate = 8000
|
|
32
|
+
|
|
31
33
|
const format = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
sampleRate,
|
|
35
|
+
bitDepth: 16,
|
|
36
|
+
channels: 1
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
const ts = new ToneStream(format)
|
|
38
40
|
|
|
39
41
|
const s = new Speaker(format)
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
ts.add([1000,
|
|
43
|
-
ts.add([1000,
|
|
43
|
+
var ns = 0
|
|
44
|
+
ns += ts.add([1000, 261.63]) // C4
|
|
45
|
+
ns += ts.add([1000, 296.33]) // D4
|
|
46
|
+
ns += ts.add([1000, 329.63]) // E4
|
|
47
|
+
|
|
48
|
+
var duration = ns / sampleRate * 1000
|
|
44
49
|
|
|
45
50
|
ts.pipe(s)
|
|
46
51
|
|
|
47
|
-
setTimeout(() => {
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
console.log("done")
|
|
54
|
+
process.exit(0)
|
|
55
|
+
}, duration)
|
|
56
|
+
|
|
48
57
|
```
|
|
49
58
|
|
|
50
59
|
Playing some DTMF tones:
|
|
@@ -54,25 +63,36 @@ const { ToneStream } = require('tone-stream')
|
|
|
54
63
|
|
|
55
64
|
const Speaker = require('speaker')
|
|
56
65
|
|
|
66
|
+
const sampleRate = 8000
|
|
67
|
+
|
|
57
68
|
const format = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
sampleRate,
|
|
70
|
+
bitDepth: 16,
|
|
71
|
+
channels: 1
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
const ts = new ToneStream(format)
|
|
64
75
|
|
|
65
76
|
const s = new Speaker(format)
|
|
66
77
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ts.add([1000, 'DTMF:
|
|
70
|
-
ts.add([500, 's'])
|
|
71
|
-
ts.add([1000, 'DTMF:
|
|
78
|
+
var ns = 0
|
|
79
|
+
|
|
80
|
+
ns += ts.add([1000, 'DTMF:1'])
|
|
81
|
+
ns += ts.add([500, 's'])
|
|
82
|
+
ns += ts.add([1000, 'DTMF:2'])
|
|
83
|
+
ns += ts.add([500, 's'])
|
|
84
|
+
ns += ts.add([1000, 'DTMF:3'])
|
|
85
|
+
ns += ts.add([500, 's'])
|
|
86
|
+
|
|
87
|
+
var duration = ns / sampleRate * 1000
|
|
72
88
|
|
|
73
89
|
ts.pipe(s)
|
|
74
90
|
|
|
75
|
-
setTimeout(() => {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
console.log("done")
|
|
93
|
+
process.exit(0)
|
|
94
|
+
}, duration)
|
|
95
|
+
|
|
76
96
|
```
|
|
77
97
|
|
|
78
98
|
Using some helper function to add miscelaneous tones
|
|
@@ -96,7 +116,7 @@ const ts = new ToneStream(format)
|
|
|
96
116
|
const s = new Speaker(format)
|
|
97
117
|
|
|
98
118
|
const tones = _.flatten([
|
|
99
|
-
utils.gen_dtmf_tones("1234567890abcdef", 100,
|
|
119
|
+
utils.gen_dtmf_tones("1234567890abcdef", 100, 100, SAMPLE_RATE),
|
|
100
120
|
utils.gen_morse_tones("Be yourself; everyone else is already taken", 880, 70, SAMPLE_RATE),
|
|
101
121
|
utils.gen_music_scale("C5 D5 E5 F5 G5 A5 B5 C6", 100, 0, SAMPLE_RATE),
|
|
102
122
|
])
|
|
@@ -120,7 +140,7 @@ ts.pipe(s)
|
|
|
120
140
|
```
|
|
121
141
|
## Events
|
|
122
142
|
|
|
123
|
-
The stream emits:
|
|
143
|
+
The stream emits events:
|
|
124
144
|
- 'empty': when there are no more tones to be played in the queue (it happens when the queue of tones is found empty)
|
|
125
145
|
- 'ended': when all tones in the queue were generated (it happens when the consumer tries to read data from the stream and there are no more tones to be generated)
|
|
126
146
|
|