fix: wakeword restart-after-kill, stale close event, stdout line buffer
parent
0a2154ddbd
commit
6f3f770783
|
|
@ -10,24 +10,30 @@ function startWakeword({ onWake }) {
|
||||||
|
|
||||||
const scriptPath = path.join(__dirname, '../python/wakeword.py');
|
const scriptPath = path.join(__dirname, '../python/wakeword.py');
|
||||||
|
|
||||||
wakewordProcess = spawn('python3', [scriptPath], {
|
const proc = spawn('python3', [scriptPath], {
|
||||||
stdio: ['pipe', 'pipe', 'pipe'],
|
stdio: ['pipe', 'pipe', 'pipe'],
|
||||||
});
|
});
|
||||||
|
wakewordProcess = proc;
|
||||||
|
|
||||||
wakewordProcess.stdout.on('data', (data) => {
|
let lineBuffer = '';
|
||||||
if (data.toString().trim() === 'WAKE') {
|
proc.stdout.on('data', (data) => {
|
||||||
onWake();
|
lineBuffer += data.toString();
|
||||||
|
const lines = lineBuffer.split('\n');
|
||||||
|
lineBuffer = lines.pop();
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.trim() === 'WAKE') onWake();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wakewordProcess.stderr.on('data', (data) => {
|
proc.stderr.on('data', (data) => {
|
||||||
console.error('[Wakeword]', data.toString().trim());
|
console.error('[Wakeword]', data.toString().trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
wakewordProcess.on('close', (code) => {
|
proc.on('close', (code, signal) => {
|
||||||
|
if (proc !== wakewordProcess) return;
|
||||||
running = false;
|
running = false;
|
||||||
wakewordProcess = null;
|
wakewordProcess = null;
|
||||||
if (code !== 0) {
|
if (code !== 0 && signal === null) {
|
||||||
setTimeout(() => startWakeword({ onWake }), 2000);
|
setTimeout(() => startWakeword({ onWake }), 2000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue