@lumiastream/wakeword 1.0.0 → 1.0.1-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.
- package/bin/wakeword +20 -5
- package/lib/voice.mjs +33 -24
- package/package.json +6 -2
package/bin/wakeword
CHANGED
|
@@ -17,13 +17,28 @@ const soxPath = path.join(
|
|
|
17
17
|
exe
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
process.execPath, // node executable
|
|
20
|
+
const child = spawn(
|
|
21
|
+
process.execPath,
|
|
23
22
|
[
|
|
24
|
-
path.join(
|
|
23
|
+
path.join(
|
|
24
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
25
|
+
"..",
|
|
26
|
+
"lib",
|
|
27
|
+
"voice.mjs"
|
|
28
|
+
),
|
|
25
29
|
soxPath,
|
|
26
30
|
...process.argv.slice(2),
|
|
27
31
|
],
|
|
28
|
-
{ stdio: "inherit" }
|
|
32
|
+
{ stdio: ["pipe", "inherit", "inherit"] }
|
|
29
33
|
);
|
|
34
|
+
|
|
35
|
+
// If you want to forward user input from this process to the child:
|
|
36
|
+
// if (process.stdin.isTTY) {
|
|
37
|
+
// process.stdin.setRawMode(false);
|
|
38
|
+
// }
|
|
39
|
+
// process.stdin.pipe(child.stdin);
|
|
40
|
+
|
|
41
|
+
// listen for hotkey events from the child process
|
|
42
|
+
child.on("message", (message) => {
|
|
43
|
+
console.log("hotkey", message);
|
|
44
|
+
});
|
package/lib/voice.mjs
CHANGED
|
@@ -14,14 +14,11 @@ const binPath = join(
|
|
|
14
14
|
console.log(binPath);
|
|
15
15
|
|
|
16
16
|
let COMMANDS = [
|
|
17
|
-
"open settings",
|
|
18
|
-
"mute audio",
|
|
19
|
-
"start recording",
|
|
20
17
|
"[unk]", // always keep an [unk] fallback!
|
|
21
18
|
];
|
|
22
19
|
|
|
23
20
|
const SAMPLE_RATE = 16_000;
|
|
24
|
-
setLogLevel(0);
|
|
21
|
+
setLogLevel(0);
|
|
25
22
|
|
|
26
23
|
// 1. load model once
|
|
27
24
|
const model = new Model("./models/vosk-model-small-en-us-0.15");
|
|
@@ -54,35 +51,47 @@ mic.on("data", (buf) => {
|
|
|
54
51
|
|
|
55
52
|
// 4. map recognised phrase ➜ action
|
|
56
53
|
function handle(phrase) {
|
|
57
|
-
|
|
54
|
+
// Igonre unk
|
|
55
|
+
if (phrase.includes("[unk]")) return;
|
|
58
56
|
if (phrase && COMMANDS.includes(phrase)) {
|
|
59
|
-
|
|
57
|
+
// Send to stdout
|
|
58
|
+
process.stdout.write(`voice|${phrase}\n`);
|
|
60
59
|
}
|
|
61
|
-
// switch (phrase) {
|
|
62
|
-
// case "open settings":
|
|
63
|
-
// process.send?.({ hotkey: "settings" });
|
|
64
|
-
// break;
|
|
65
|
-
// case "mute audio":
|
|
66
|
-
// process.send?.({ hotkey: "mute" });
|
|
67
|
-
// break;
|
|
68
|
-
// case "start recording":
|
|
69
|
-
// process.send?.({ hotkey: "record" });
|
|
70
|
-
// break;
|
|
71
|
-
// }
|
|
72
60
|
}
|
|
73
61
|
|
|
74
62
|
const updateGrammar = (grammar) => {
|
|
75
|
-
COMMANDS = grammar;
|
|
63
|
+
COMMANDS = [...grammar, "[unk]"];
|
|
76
64
|
rec = new Recognizer({
|
|
77
65
|
model,
|
|
78
66
|
sampleRate: SAMPLE_RATE,
|
|
79
|
-
grammar:
|
|
67
|
+
grammar: COMMANDS,
|
|
80
68
|
});
|
|
81
|
-
console.log(COMMANDS);
|
|
82
69
|
};
|
|
70
|
+
// Listen for CLI input to update grammar at runtime
|
|
71
|
+
import readline from "node:readline";
|
|
83
72
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
// Set up readline interface for stdin
|
|
74
|
+
const rl = readline.createInterface({
|
|
75
|
+
input: process.stdin,
|
|
76
|
+
output: process.stdout,
|
|
77
|
+
terminal: false,
|
|
78
|
+
});
|
|
87
79
|
|
|
88
|
-
|
|
80
|
+
// Listen for lines from stdin
|
|
81
|
+
rl.on("line", (line) => {
|
|
82
|
+
const trimmed = line.trim();
|
|
83
|
+
// Example: update,open settings,mute audio,start recording
|
|
84
|
+
if (trimmed.startsWith("update")) {
|
|
85
|
+
const parts = trimmed.split(",");
|
|
86
|
+
if (parts.length > 1) {
|
|
87
|
+
// Remove the "update" command and use the rest as grammar
|
|
88
|
+
const newGrammar = parts
|
|
89
|
+
.slice(1)
|
|
90
|
+
.map((s) => s.trim())
|
|
91
|
+
.filter(Boolean);
|
|
92
|
+
if (newGrammar.length > 0) {
|
|
93
|
+
updateGrammar(newGrammar);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumiastream/wakeword",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/voice.mjs",
|
|
6
6
|
"bin": {
|
|
7
|
-
"wakeword": "bin/wakeword"
|
|
7
|
+
"@lumiastream/wakeword": "bin/wakeword"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin/",
|
|
@@ -19,5 +19,9 @@
|
|
|
19
19
|
"@lumiastream/wakeword-darwin": "file:./binaries/soxmac",
|
|
20
20
|
"@lumiastream/wakeword-linux": "file:./binaries/soxlinux",
|
|
21
21
|
"@lumiastream/wakeword-win32": "file:./binaries/sox.exe"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@lumiastream/record": "^1.0.1",
|
|
25
|
+
"vosk": "^0.3.39"
|
|
22
26
|
}
|
|
23
27
|
}
|