@lumiastream/wakeword 1.1.1 → 1.1.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/binaries/sox.exe +0 -0
- package/binaries/soxlinux +0 -0
- package/binaries/soxmac +0 -0
- package/lib/recorders/sox.js +69 -51
- package/lib/voice.js +9 -1
- package/package.json +1 -1
package/binaries/sox.exe
CHANGED
|
File without changes
|
package/binaries/soxlinux
CHANGED
|
File without changes
|
package/binaries/soxmac
CHANGED
|
File without changes
|
package/lib/recorders/sox.js
CHANGED
|
@@ -1,53 +1,71 @@
|
|
|
1
1
|
export default (options) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
2
|
+
let cmd = "sox";
|
|
3
|
+
|
|
4
|
+
if (options.binPath) {
|
|
5
|
+
cmd = options.binPath;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Build common output/encoding args
|
|
9
|
+
let args = [
|
|
10
|
+
"--no-show-progress",
|
|
11
|
+
"--rate",
|
|
12
|
+
options.sampleRate,
|
|
13
|
+
"--channels",
|
|
14
|
+
options.channels,
|
|
15
|
+
"--encoding",
|
|
16
|
+
"signed-integer",
|
|
17
|
+
"--bits",
|
|
18
|
+
"16",
|
|
19
|
+
"--type",
|
|
20
|
+
options.audioType,
|
|
21
|
+
"-", // write to stdout
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
if (options.bufferSize) {
|
|
25
|
+
args.push("--buffer", options.bufferSize);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (options.endOnSilence) {
|
|
29
|
+
args = args.concat([
|
|
30
|
+
"silence",
|
|
31
|
+
"1",
|
|
32
|
+
"0.1",
|
|
33
|
+
options.thresholdStart || options.threshold + "%",
|
|
34
|
+
"1",
|
|
35
|
+
options.silence,
|
|
36
|
+
options.thresholdEnd || options.threshold + "%",
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (options.arguments) {
|
|
41
|
+
args = args.concat(options.arguments);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const spawnOptions = {};
|
|
45
|
+
|
|
46
|
+
// Prepend input spec based on platform
|
|
47
|
+
const platform = process.platform;
|
|
48
|
+
if (platform === "win32") {
|
|
49
|
+
const dev = options.device ?? "default";
|
|
50
|
+
args.unshift("-t", "waveaudio", dev);
|
|
51
|
+
// AUDIODEV sometimes respected on Windows; keep for compatibility
|
|
52
|
+
spawnOptions.env = { ...process.env, AUDIODEV: dev };
|
|
53
|
+
} else if (platform === "darwin") {
|
|
54
|
+
// CoreAudio input
|
|
55
|
+
if (options.device) {
|
|
56
|
+
args.unshift("-t", "coreaudio", options.device);
|
|
57
|
+
} else {
|
|
58
|
+
// Explicitly select CoreAudio default device for reliability
|
|
59
|
+
args.unshift("-t", "coreaudio", "default");
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
// Linux: ALSA default or specified
|
|
63
|
+
if (options.device) {
|
|
64
|
+
args.unshift("-t", "alsa", options.device);
|
|
65
|
+
} else {
|
|
66
|
+
args.unshift("-d");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { cmd, args, spawnOptions };
|
|
53
71
|
};
|
package/lib/voice.js
CHANGED
|
@@ -76,10 +76,18 @@ if (audioDevice !== null) {
|
|
|
76
76
|
// Windows: default to device 0 if not specified
|
|
77
77
|
recArgs.device = "0";
|
|
78
78
|
console.error("Using default Windows audio device: 0");
|
|
79
|
-
console.error(
|
|
79
|
+
console.error(
|
|
80
|
+
"To specify a different device, use: AUDIO_DEVICE=<device_id> or pass as 3rd argument"
|
|
81
|
+
);
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
const mic = record.record(recArgs).stream();
|
|
85
|
+
// Handle recorder (SoX) errors to avoid unhandled 'error' events
|
|
86
|
+
mic.on("error", (err) => {
|
|
87
|
+
const msg = typeof err === "string" ? err : err?.message || String(err);
|
|
88
|
+
console.error(`[wakeword] audio stream error: ${msg}`);
|
|
89
|
+
process.exit(2);
|
|
90
|
+
});
|
|
83
91
|
// Define a confidence threshold for individual words.
|
|
84
92
|
// You might need to adjust this value based on your specific use case.
|
|
85
93
|
let WORD_CONFIDENCE_THRESHOLD = 0.7;
|