From 091c4f9becfbe8506ebd0a16445bf7713f189902 Mon Sep 17 00:00:00 2001 From: Apher Date: Mon, 6 Jul 2026 23:46:37 +0000 Subject: [PATCH] Handle python output --- src/scripts/py/pythonOutput.js | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/scripts/py/pythonOutput.js diff --git a/src/scripts/py/pythonOutput.js b/src/scripts/py/pythonOutput.js new file mode 100644 index 0000000..e09e33b --- /dev/null +++ b/src/scripts/py/pythonOutput.js @@ -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 };