Handle python output
This commit is contained in:
parent
990589a776
commit
091c4f9bec
41
src/scripts/py/pythonOutput.js
Normal file
41
src/scripts/py/pythonOutput.js
Normal file
@ -0,0 +1,41 @@
|
||||
// pythonOutput.js
|
||||
let buffer = "";
|
||||
|
||||
function handlePythonOutput(chunk, onMessage) {
|
||||
buffer += chunk;
|
||||
const lines = buffer.split("\n");
|
||||
buffer = lines.pop() || "";
|
||||
|
||||
for (const line of lines) {
|
||||
if (!line.trim()) continue;
|
||||
|
||||
try {
|
||||
const msg = JSON.parse(line);
|
||||
switch (msg.event) {
|
||||
case "ready":
|
||||
console.log("Python ready");
|
||||
break;
|
||||
case "wakeword":
|
||||
console.log(`Wakeword detected: ${msg.model} (${msg.score})`);
|
||||
break;
|
||||
case "partial":
|
||||
console.log("Partial:", msg.text);
|
||||
break;
|
||||
case "text":
|
||||
case "final":
|
||||
console.log("Transcript:", msg.text);
|
||||
onMessage?.(msg).catch(console.error);
|
||||
break;
|
||||
case "done":
|
||||
console.log("Back to wakeword mode");
|
||||
break;
|
||||
default:
|
||||
console.log("[PY]", line);
|
||||
}
|
||||
} catch {
|
||||
console.log("[PY]", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { handlePythonOutput };
|
||||
Loading…
Reference in New Issue
Block a user