@lumiastream/wakeword 1.1.4 → 1.1.5-alpha.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.
@@ -5,10 +5,13 @@ import { existsSync } from "node:fs";
5
5
 
6
6
  const here = dirname(fileURLToPath(import.meta.url));
7
7
 
8
+ const ASAR_TOKEN = "app.asar";
9
+ const ASAR_UNPACKED_TOKEN = "app.asar.unpacked";
10
+
8
11
  function unpacked(p) {
9
- return p.includes("app.asar")
10
- ? p.replace("app.asar", "app.asar.unpacked")
11
- : p;
12
+ if (!p || !p.includes(ASAR_TOKEN)) return p;
13
+ if (p.includes(ASAR_UNPACKED_TOKEN)) return p;
14
+ return p.replace(ASAR_TOKEN, ASAR_UNPACKED_TOKEN);
12
15
  }
13
16
 
14
17
  const exeName = { win32: "sox.exe", darwin: "soxmac", linux: "soxlinux" }[
package/lib/voice.js CHANGED
@@ -1,19 +1,50 @@
1
- import { Model, Recognizer, setLogLevel } from "vosk-koffi";
2
1
  import record from "./record.js";
3
- import { dirname, join } from "node:path";
2
+ import koffi from "koffi";
3
+ import { delimiter, dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { existsSync, chmodSync } from "node:fs";
6
6
  import readline from "node:readline";
7
7
 
8
+ // Ensure native libs can load from app.asar.unpacked when packaged
9
+ const maybeUnpackedPath = (libPath) => {
10
+ if (typeof libPath !== "string") return libPath;
11
+ if (!libPath.includes(ASAR_TOKEN)) return libPath;
12
+ if (libPath.includes(ASAR_UNPACKED_TOKEN)) return libPath;
13
+ const unpacked = libPath.replace(ASAR_TOKEN, ASAR_UNPACKED_TOKEN);
14
+ return existsSync(unpacked) ? unpacked : libPath;
15
+ };
16
+ const ensureWinBinOnPath = (libPath) => {
17
+ if (process.platform !== "win32") return;
18
+ const dir = dirname(libPath);
19
+ const current = process.env.Path || process.env.PATH || "";
20
+ const parts = current.split(delimiter).filter(Boolean);
21
+ if (!parts.includes(dir)) {
22
+ process.env.Path = [dir, ...parts].join(delimiter);
23
+ }
24
+ };
25
+ const originalKoffiLoad = koffi.load.bind(koffi);
26
+ koffi.load = (libPath, ...rest) => {
27
+ const resolved = maybeUnpackedPath(libPath);
28
+ if (resolved !== libPath && typeof resolved === "string") {
29
+ ensureWinBinOnPath(resolved);
30
+ }
31
+ return originalKoffiLoad(resolved, ...rest);
32
+ };
33
+
34
+ const { Model, Recognizer, setLogLevel } = await import("vosk-koffi");
35
+
8
36
  /* ------------------------------------------------------------------ */
9
37
  /* 0. Helpers */
10
38
  /* ------------------------------------------------------------------ */
11
39
  const here = dirname(fileURLToPath(import.meta.url));
12
40
 
41
+ const ASAR_TOKEN = "app.asar";
42
+ const ASAR_UNPACKED_TOKEN = "app.asar.unpacked";
43
+
13
44
  function unpacked(p) {
14
- return p.includes("app.asar")
15
- ? p.replace("app.asar", "app.asar.unpacked")
16
- : p;
45
+ if (!p || !p.includes(ASAR_TOKEN)) return p;
46
+ if (p.includes(ASAR_UNPACKED_TOKEN)) return p;
47
+ return p.replace(ASAR_TOKEN, ASAR_UNPACKED_TOKEN);
17
48
  }
18
49
 
19
50
  const UNKNOWN_TOKEN = "[unk]";
@@ -29,12 +60,7 @@ const defaultExeName = {
29
60
  darwin: "soxmac",
30
61
  linux: "soxlinux",
31
62
  }[process.platform];
32
- const envExeOverride =
33
- process.platform === "win32" && process.env.LUMIA_WIN_MIC_ALIAS_NAME
34
- ? process.env.LUMIA_WIN_MIC_ALIAS_NAME.trim()
35
- : null;
36
- const exeName =
37
- envExeOverride && envExeOverride.length ? envExeOverride : defaultExeName;
63
+ const exeName = defaultExeName;
38
64
  const MATCH_SENTENCE = toBool(process.env.LUMIA_VOICE_MATCH_SENTENCE);
39
65
 
40
66
  /* Priority for sox path: argv[2] → fallback to sibling binaries/<exe> */
@@ -238,7 +264,7 @@ rl.on("line", (line) => {
238
264
  .split(",")
239
265
  .slice(1)
240
266
  .map((s) => normalizePhrase(s))
241
- .filter(Boolean);
267
+ .filter(Boolean);
242
268
 
243
269
  if (!phrases.length) return;
244
270
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumiastream/wakeword",
3
- "version": "1.1.4",
3
+ "version": "1.1.5-alpha.2",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -15,6 +15,7 @@
15
15
  "start": "node lib/voice.js"
16
16
  },
17
17
  "dependencies": {
18
+ "koffi": "^2.8.6",
18
19
  "vosk-koffi": "^1.1.1"
19
20
  }
20
21
  }