const { spawn } = require('child_process'); const fs = require('fs'); const config = JSON.parse(fs.readFileSync('./config.json', 'utf8')); const py = spawn('python', ['wakeword.py', JSON.stringify(config)], { stdio: ['ignore', 'pipe', 'pipe'] }); let buffer = ''; py.stdout.on('data', (data) => { buffer += data.toString(); const lines = buffer.split('\n'); buffer = lines.pop(); for (const line of lines) { if (!line.trim()) continue; try { const msg = JSON.parse(line); if (msg.event === 'ready') { console.log('Python ready'); } else if (msg.event === 'wakeword') { console.log(`Wakeword detected: ${msg.model} (${msg.score})`); } else if (msg.event === 'partial') { console.log('Partial:', msg.text); } else if (msg.event === 'text' || msg.event === 'final') { console.log('Transcript:', msg.text); } else if (msg.event === 'done') { console.log('Back to wakeword mode'); } } catch { console.log('[PY]', line); } } }); py.stderr.on('data', (data) => { console.error('[PY ERR]', data.toString()); }); py.on('close', (code) => { console.log('Python exited with code', code); });