tone-stream 1.6.0 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tone-stream",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "A simple audio tone stream library",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -22,13 +22,20 @@
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
24
  "lodash": "^4.17.21",
25
- "speaker": "^0.5.1"
25
+ "speaker": "^0.5.1",
26
+ "wav": "^1.0.2"
26
27
  },
27
28
  "dependencies": {
28
29
  "dtmf-detection-stream": "^1.10.0",
29
30
  "morse-node": "^0.1.1",
30
31
  "note-to-frequency": "^1.4.1",
31
- "spec-read-stream": "^1.2.0",
32
- "wav": "^1.0.2"
33
- }
32
+ "spec-read-stream": "^1.2.8"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "src",
37
+ "lib",
38
+ "README.md",
39
+ "LICENSE"
40
+ ]
34
41
  }
package/.editorconfig DELETED
@@ -1,9 +0,0 @@
1
- root = true
2
-
3
-
4
- [Makefile]
5
- indent_style = tab
6
-
7
- [*]
8
- indent_style = space
9
- indent_size = 2
@@ -1,28 +0,0 @@
1
- const { ToneStream } = require('../index.js')
2
- const DtmfDetectionStream = require('dtmf-detection-stream')
3
-
4
- const format = {
5
- sampleRate: 8000,
6
- bitDepth: 16,
7
- channels: 1,
8
- }
9
-
10
- const ts = new ToneStream(format)
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)
23
- })
24
-
25
- ts.on('data', data => {
26
- dds.write(data)
27
- })
28
-
@@ -1,22 +0,0 @@
1
- const { ToneStream } = require('../index.js')
2
- const Speaker = require('speaker')
3
-
4
- const format = {
5
- sampleRate: 8000,
6
- bitDepth: 16,
7
- channels: 1
8
- }
9
-
10
- const ts = new ToneStream(format)
11
-
12
- const s = new Speaker(format)
13
-
14
- ts.add([2000, 261.63]) // C4
15
- ts.add([1000, 's']) // silence
16
- ts.add([2000, 296.33]) // D4
17
- ts.add([1000, 's']) // silence
18
- ts.add([2000, 329.63]) // E4
19
-
20
- ts.pipe(s)
21
-
22
- setTimeout(() => {}, 2000)
@@ -1,55 +0,0 @@
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
- '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
11
- `)
12
- }
13
-
14
-
15
- if(process.argv.length != 7) {
16
- usage()
17
- process.exit(1)
18
- }
19
-
20
- const dtmfSequence = process.argv[2]
21
- const outputFile = process.argv[3]
22
- const sampleRate = parseInt(process.argv[4])
23
- const bitDepth = parseInt(process.argv[5])
24
- const channels = parseInt(process.argv[6])
25
-
26
- const format = {
27
- sampleRate,
28
- bitDepth,
29
- channels,
30
- }
31
-
32
- console.log("format:", format)
33
-
34
- const tones = utils.gen_dtmf_tones(dtmfSequence, 100, 100, sampleRate)
35
-
36
- console.log("tones:", tones)
37
-
38
- const fileWriter = new wav.FileWriter(outputFile, format)
39
-
40
- const ts = new ToneStream(format)
41
-
42
- const speaker = new Speaker(format)
43
-
44
- ts.pipe(speaker)
45
- ts.pipe(fileWriter)
46
-
47
- ts.concat(tones)
48
- ts.add([ sampleRate, 's' ])
49
-
50
- ts.on('empty', () => {
51
- console.log('end_of_audio')
52
- setTimeout(() => {
53
- fileWriter.end()
54
- }, 1000)
55
- })
@@ -1,41 +0,0 @@
1
- const { ToneStream } = require('../index.js')
2
- const Speaker = require('speaker')
3
-
4
- const format = {
5
- sampleRate: 8000,
6
- bitDepth: 16,
7
- channels: 1
8
- }
9
-
10
- const ts = new ToneStream(format)
11
-
12
- const s = new Speaker(format)
13
-
14
- var tones = [
15
- [1000, 'DTMF:1'],
16
- [1000, 'DTMF:2'],
17
- [1000, 'DTMF:3'],
18
- [1000, 'DTMF:4'],
19
- [1000, 'DTMF:5'],
20
- [1000, 'DTMF:6'],
21
- [1000, 'DTMF:7'],
22
- [1000, 'DTMF:8'],
23
- [1000, 'DTMF:9'],
24
- [1000, 'DTMF:0'],
25
- [1000, 'DTMF:a'],
26
- [1000, 'DTMF:b'],
27
- [1000, 'DTMF:c'],
28
- [1000, 'DTMF:d'],
29
- [1000, 'DTMF:*'],
30
- [1000, 'DTMF:#'],
31
- ]
32
-
33
- ts.concat(tones)
34
-
35
- ts.on('empty', () => {
36
- console.log("Got event 'empty'. Reversing tones.")
37
- tones.reverse()
38
- ts.concat(tones)
39
- })
40
-
41
- ts.pipe(s)
@@ -1,26 +0,0 @@
1
- const { ToneStream, utils } = require('../index.js')
2
- const Speaker = require('speaker')
3
-
4
- const SAMPLE_RATE = 8000
5
-
6
- const format = {
7
- sampleRate: SAMPLE_RATE,
8
- bitDepth: 16,
9
- channels: 1
10
- }
11
-
12
- const ts = new ToneStream(format)
13
-
14
- const s = new Speaker(format)
15
-
16
- var tones = utils.gen_dtmf_tones("1234576890abcd*#", 50, 50, SAMPLE_RATE)
17
-
18
- ts.concat(tones)
19
-
20
- ts.on('empty', () => {
21
- console.log("Got event 'empty'. Reversing tones.")
22
- tones.reverse()
23
- ts.concat(tones)
24
- })
25
-
26
- ts.pipe(s)
@@ -1,27 +0,0 @@
1
- const { ToneStream, utils } = require('../index.js')
2
- const Speaker = require('speaker')
3
-
4
- const SAMPLE_RATE = 8000
5
-
6
- const format = {
7
- sampleRate: SAMPLE_RATE,
8
- bitDepth: 16,
9
- channels: 1
10
- }
11
-
12
- const ts = new ToneStream(format)
13
-
14
- const s = new Speaker(format)
15
-
16
- var tones = utils.gen_morse_tones("What we've got here is failure to communicate", "C6", 70, SAMPLE_RATE)
17
- tones.push([8000, 's'])
18
-
19
- ts.concat(tones)
20
-
21
- ts.on('empty', () => {
22
- console.log("Got event 'empty'. Reversing tones.")
23
- tones.reverse()
24
- ts.concat(tones)
25
- })
26
-
27
- ts.pipe(s)
@@ -1,30 +0,0 @@
1
- const { ToneStream, utils } = require('../index.js')
2
- const Speaker = require('speaker')
3
-
4
- const SAMPLE_RATE = 8000
5
-
6
- const format = {
7
- sampleRate: SAMPLE_RATE,
8
- bitDepth: 16,
9
- channels: 1
10
- }
11
-
12
- const ts = new ToneStream(format)
13
-
14
- const s = new Speaker(format)
15
-
16
- const notes = "C4 D4 E4 F4 G4 A4 B4 C5"
17
- const note_duration = 100 // milliseconds
18
- const rest_duration = 0 // milliseconds
19
-
20
- const tones = utils.gen_music_scale(notes, note_duration, rest_duration, SAMPLE_RATE)
21
-
22
- ts.concat(tones)
23
-
24
- ts.on('empty', () => {
25
- console.log("Got event 'empty'. Reversing notes.")
26
- tones.reverse()
27
- ts.concat(tones)
28
- })
29
-
30
- ts.pipe(s)
@@ -1,53 +0,0 @@
1
- const { ToneStream } = require('../index.js')
2
-
3
- const Speaker = require('speaker')
4
-
5
- const assert = require('assert')
6
-
7
- const format = {
8
- sampleRate: 8000,
9
- bitDepth: 16,
10
- channels: 1
11
- }
12
-
13
- const opts = {
14
- stay_alive: true,
15
- }
16
-
17
- const ts = new ToneStream(format, opts)
18
-
19
- const s = new Speaker(format)
20
-
21
- ts.add([2000, 261.63]) // C4
22
- ts.add([2000, 296.33]) // D4
23
- ts.add([2000, 329.63]) // E4
24
-
25
- var b
26
-
27
- /*
28
- Be aware that when you call method 'read(N)' on a stream, you will get N bytes, not N samples.
29
- So if you want to get bytes for 10 samples, you should ask: ts.read(10 * (bitDepth/8) * channels)
30
- */
31
-
32
- b = ts.read(500)
33
- assert(b.length == 500)
34
- s.write(b)
35
-
36
- b = ts.read(700)
37
- assert(b.length == 700)
38
- s.write(b)
39
-
40
- b = ts.read(160)
41
- assert(b.length == 160)
42
- s.write(b)
43
-
44
- b = ts.read(140)
45
- assert(b.length == 140)
46
- s.write(b)
47
-
48
- b = ts.read(12000)
49
- assert(b.length == 12000) // this will be filled with silence (zero) after all items are consumed.
50
- s.write(b)
51
-
52
- setTimeout(() => {}, 2000)
53
-