tone-stream 1.12.0 → 1.14.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/index.js +3 -0
- package/lib/utils.js +35 -0
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -75,12 +75,15 @@ class ToneStream extends Readable {
|
|
|
75
75
|
var buf_idx = 0;
|
|
76
76
|
|
|
77
77
|
if (!specs) {
|
|
78
|
+
/*
|
|
78
79
|
for (var j = 0; j < numSamples * this.channels; j++) {
|
|
79
80
|
let offset = j * sampleSize * this.channels;
|
|
80
81
|
setter(0, offset);
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
this.push(buf);
|
|
85
|
+
*/
|
|
86
|
+
this.push(null)
|
|
84
87
|
return;
|
|
85
88
|
}
|
|
86
89
|
|
package/lib/utils.js
CHANGED
|
@@ -9,6 +9,17 @@ const tone2freq = tone => {
|
|
|
9
9
|
return noteToFrequency(tone)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
const asciiToBinary = char => {
|
|
13
|
+
// Get the ASCII value of the character
|
|
14
|
+
const asciiValue = char.charCodeAt(0)
|
|
15
|
+
|
|
16
|
+
// Convert the ASCII value to a binary string and pad with leading zeros to ensure it's 8 bits
|
|
17
|
+
const binaryString = asciiValue.toString(2).padStart(8, '0')
|
|
18
|
+
|
|
19
|
+
// Return the binary string
|
|
20
|
+
return binaryString
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
const wpm2rate = (wpm, sampleRate) => {
|
|
13
24
|
// WPM = 2.4 * (Dots per second)
|
|
14
25
|
// Ref: http://www.nu-ware.com/NuCode%20Help/index.html?morse_code_structure_and_timing_.htm
|
|
@@ -103,9 +114,33 @@ const gen_music_scale = (notes, note_duration, rest_duration, sampleRate) => {
|
|
|
103
114
|
return tones
|
|
104
115
|
}
|
|
105
116
|
|
|
117
|
+
const gen_binary_tones_from_text = (text, tone_duration, zero_freq, one_freq, sampleRate) => {
|
|
118
|
+
const tones = []
|
|
119
|
+
const samples_per_tone = Math.round(tone_duration * sampleRate / 1000)
|
|
120
|
+
|
|
121
|
+
const binaries = text.split("").map(asciiToBinary).join("").split("")
|
|
122
|
+
console.log("binaries", binaries)
|
|
123
|
+
const freqs = binaries.map(binary => binary == '0' ? zero_freq : one_freq)
|
|
124
|
+
console.log("freqs", freqs)
|
|
125
|
+
|
|
126
|
+
var last = null
|
|
127
|
+
for (var i=0 ; i<freqs.length; i++) {
|
|
128
|
+
var freq = freqs[i]
|
|
129
|
+
if(i > 0 && last == freq) {
|
|
130
|
+
tones.push([samples_per_tone, 's'])
|
|
131
|
+
}
|
|
132
|
+
tones.push([samples_per_tone, freq])
|
|
133
|
+
last = freq
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return tones
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
106
140
|
|
|
107
141
|
module.exports = {
|
|
108
142
|
gen_morse_tones,
|
|
109
143
|
gen_dtmf_tones,
|
|
110
144
|
gen_music_scale,
|
|
145
|
+
gen_binary_tones_from_text,
|
|
111
146
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tone-stream",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "A simple audio tone stream library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"author": "MayamaTakeshi",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@mayama/audio-utils": "^1.2.0",
|
|
25
|
+
"dtmf-detection-stream": "^1.16.2",
|
|
24
26
|
"lodash": "^4.17.21",
|
|
25
27
|
"speaker": "^0.5.1",
|
|
26
|
-
"wav": "^1.0.2"
|
|
27
|
-
"dtmf-detection-stream": "^1.10.0"
|
|
28
|
+
"wav": "^1.0.2"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"morse-node": "^0.1.1",
|