@lumiastream/wakeword 1.0.1-alpha.8 → 1.0.1-alpha.9
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/lib/record.js +0 -1
- package/lib/voice.js +17 -4
- package/package.json +1 -1
package/lib/record.js
CHANGED
package/lib/voice.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Model, Recognizer, setLogLevel } from "vosk-koffi";
|
|
2
2
|
import record from "./record.js";
|
|
3
|
-
import { join } from "node:path";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
4
8
|
|
|
5
9
|
const binPath = join(
|
|
6
10
|
"binaries",
|
|
@@ -11,8 +15,6 @@ const binPath = join(
|
|
|
11
15
|
: "soxlinux"
|
|
12
16
|
);
|
|
13
17
|
|
|
14
|
-
console.log(binPath);
|
|
15
|
-
|
|
16
18
|
let COMMANDS = [
|
|
17
19
|
"blue",
|
|
18
20
|
"[unk]", // always keep an [unk] fallback!
|
|
@@ -22,7 +24,18 @@ const SAMPLE_RATE = 16_000;
|
|
|
22
24
|
setLogLevel(0);
|
|
23
25
|
|
|
24
26
|
// 1. load model once
|
|
25
|
-
|
|
27
|
+
let modelPath = join(__dirname, "..", "models", "vosk-model-small-en-us-0.15");
|
|
28
|
+
|
|
29
|
+
/* If the file is running from inside app.asar we need the unpacked copy */
|
|
30
|
+
if (modelPath.includes("app.asar")) {
|
|
31
|
+
modelPath = modelPath.replace("app.asar", "app.asar.unpacked");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!existsSync(modelPath)) {
|
|
35
|
+
throw new Error(`Vosk model not found at ${modelPath}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const model = new Model(modelPath);
|
|
26
39
|
|
|
27
40
|
// 2. build a grammar recognizer
|
|
28
41
|
let rec = new Recognizer({
|