@lumiastream/wakeword 1.1.4 → 1.1.5-alpha.1

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.
Files changed (2) hide show
  1. package/lib/voice.js +31 -9
  2. package/package.json +2 -1
package/lib/voice.js CHANGED
@@ -1,10 +1,37 @@
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("app.asar")) return libPath;
12
+ const unpacked = libPath.replace("app.asar", "app.asar.unpacked");
13
+ return existsSync(unpacked) ? unpacked : libPath;
14
+ };
15
+ const ensureWinBinOnPath = (libPath) => {
16
+ if (process.platform !== "win32") return;
17
+ const dir = dirname(libPath);
18
+ const current = process.env.Path || process.env.PATH || "";
19
+ const parts = current.split(delimiter).filter(Boolean);
20
+ if (!parts.includes(dir)) {
21
+ process.env.Path = [dir, ...parts].join(delimiter);
22
+ }
23
+ };
24
+ const originalKoffiLoad = koffi.load.bind(koffi);
25
+ koffi.load = (libPath, ...rest) => {
26
+ const resolved = maybeUnpackedPath(libPath);
27
+ if (resolved !== libPath && typeof resolved === "string") {
28
+ ensureWinBinOnPath(resolved);
29
+ }
30
+ return originalKoffiLoad(resolved, ...rest);
31
+ };
32
+
33
+ const { Model, Recognizer, setLogLevel } = await import("vosk-koffi");
34
+
8
35
  /* ------------------------------------------------------------------ */
9
36
  /* 0. Helpers */
10
37
  /* ------------------------------------------------------------------ */
@@ -29,12 +56,7 @@ const defaultExeName = {
29
56
  darwin: "soxmac",
30
57
  linux: "soxlinux",
31
58
  }[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;
59
+ const exeName = defaultExeName;
38
60
  const MATCH_SENTENCE = toBool(process.env.LUMIA_VOICE_MATCH_SENTENCE);
39
61
 
40
62
  /* Priority for sox path: argv[2] → fallback to sibling binaries/<exe> */
@@ -238,7 +260,7 @@ rl.on("line", (line) => {
238
260
  .split(",")
239
261
  .slice(1)
240
262
  .map((s) => normalizePhrase(s))
241
- .filter(Boolean);
263
+ .filter(Boolean);
242
264
 
243
265
  if (!phrases.length) return;
244
266
 
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.1",
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
  }