Handle python output

This commit is contained in:
Apher 2026-07-06 23:46:37 +00:00
parent 990589a776
commit 091c4f9bec

View 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 };