@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 CHANGED
File without changes
package/binaries/soxlinux CHANGED
File without changes
package/binaries/soxmac CHANGED
File without changes
@@ -1,53 +1,71 @@
1
1
  export default (options) => {
2
- let cmd = "sox";
3
-
4
- if (options.binPath) {
5
- cmd = options.binPath;
6
- }
7
-
8
- let args = [
9
- "--no-show-progress", // show no progress
10
- "--rate",
11
- options.sampleRate, // sample rate
12
- "--channels",
13
- options.channels, // channels
14
- "--encoding",
15
- "signed-integer", // sample encoding
16
- "--bits",
17
- "16", // precision (bits)
18
- "--type",
19
- options.audioType, // audio type
20
- "-", // pipe
21
- ];
22
-
23
- if (options.bufferSize) {
24
- args.push("--buffer", options.bufferSize);
25
- }
26
-
27
- if (options.endOnSilence) {
28
- args = args.concat([
29
- "silence",
30
- "1",
31
- "0.1",
32
- options.thresholdStart || options.threshold + "%",
33
- "1",
34
- options.silence,
35
- options.thresholdEnd || options.threshold + "%",
36
- ]);
37
- }
38
-
39
- if (options.arguments) {
40
- args = args.concat(options.arguments);
41
- }
42
-
43
- const spawnOptions = {};
44
-
45
- if (options.device) {
46
- args.unshift("-t", "waveaudio", options.device);
47
- spawnOptions.env = { ...process.env, AUDIODEV: options.device };
48
- } else {
49
- args.unshift("--default-device");
50
- }
51
-
52
- return { cmd, args, spawnOptions };
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("To specify a different device, use: AUDIO_DEVICE=<device_id> or pass as 3rd argument");
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumiastream/wakeword",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "files": [