tone-stream 1.8.0 → 1.10.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/README.md +18 -0
- package/index.js +14 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# tone-stream
|
|
2
2
|
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
3
5
|
A simple node.js tone stream library.
|
|
4
6
|
|
|
5
7
|
You can specify frequencies to be played by adding items in the format:
|
|
@@ -10,7 +12,14 @@ or DTMF tones:
|
|
|
10
12
|
```
|
|
11
13
|
[NUMBER_OF_SAMPLES, 'DTMF:ID']
|
|
12
14
|
```
|
|
15
|
+
You can add multiple of such tones and they will be enequeued and played in order.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
```
|
|
19
|
+
npm i tone-stream
|
|
20
|
+
```
|
|
13
21
|
|
|
22
|
+
## Sample usage
|
|
14
23
|
|
|
15
24
|
Playing some musical notes:
|
|
16
25
|
|
|
@@ -109,3 +118,12 @@ console.log("Starting playing tones")
|
|
|
109
118
|
ts.pipe(s)
|
|
110
119
|
|
|
111
120
|
```
|
|
121
|
+
## Events
|
|
122
|
+
|
|
123
|
+
The stream emits:
|
|
124
|
+
- 'empty': when there are no more tones to be played in the queue (it happens when the queue of tones is found empty)
|
|
125
|
+
- '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
|
+
|
|
127
|
+
## More examples
|
|
128
|
+
|
|
129
|
+
See [here](https://github.com/MayamaTakeshi/tone-stream/tree/master/examples).
|
package/index.js
CHANGED
|
@@ -4,6 +4,8 @@ const SpecReadStream = require("spec-read-stream");
|
|
|
4
4
|
|
|
5
5
|
const DTMF = require("./lib/dtmf");
|
|
6
6
|
|
|
7
|
+
const EventEmitter = require('events');
|
|
8
|
+
|
|
7
9
|
class ToneStream extends Readable {
|
|
8
10
|
constructor(format, opts) {
|
|
9
11
|
super();
|
|
@@ -26,16 +28,22 @@ class ToneStream extends Readable {
|
|
|
26
28
|
this.specReadStream = new SpecReadStream();
|
|
27
29
|
|
|
28
30
|
this.currentSample = 0;
|
|
31
|
+
|
|
32
|
+
this.pending_ended = false;
|
|
33
|
+
|
|
34
|
+
this.eventEmitter = new EventEmitter();
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
add(spec) {
|
|
32
38
|
this.specReadStream.add(spec);
|
|
39
|
+
this.pending_ended = true
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
concat(specs) {
|
|
36
43
|
specs.forEach((spec) => {
|
|
37
44
|
this.specReadStream.add(spec);
|
|
38
45
|
});
|
|
46
|
+
this.pending_ended = true
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
on(evt, cb) {
|
|
@@ -43,6 +51,8 @@ class ToneStream extends Readable {
|
|
|
43
51
|
|
|
44
52
|
if (evt == "empty") {
|
|
45
53
|
this.specReadStream.on(evt, cb);
|
|
54
|
+
} else if (evt == "ended") {
|
|
55
|
+
this.eventEmitter.on(evt, cb);
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
|
|
@@ -66,6 +76,10 @@ class ToneStream extends Readable {
|
|
|
66
76
|
var buf_idx = 0;
|
|
67
77
|
|
|
68
78
|
if (!specs) {
|
|
79
|
+
if(this.pending_ended) {
|
|
80
|
+
this.pending_ended = false
|
|
81
|
+
this.eventEmitter.emit("ended")
|
|
82
|
+
}
|
|
69
83
|
if (this.opts && this.opts.stay_alive) {
|
|
70
84
|
for (var j = 0; j < numSamples * this.channels; j++) {
|
|
71
85
|
let offset = j * sampleSize * this.channels;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tone-stream",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "A simple audio tone stream library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"lodash": "^4.17.21",
|
|
25
25
|
"speaker": "^0.5.1",
|
|
26
|
-
"wav": "^1.0.2"
|
|
26
|
+
"wav": "^1.0.2",
|
|
27
|
+
"dtmf-detection-stream": "^1.10.0"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"dtmf-detection-stream": "^1.10.0",
|
|
30
30
|
"morse-node": "^0.1.1",
|
|
31
31
|
"note-to-frequency": "^1.4.1",
|
|
32
32
|
"spec-read-stream": "^1.2.8"
|