diff --git a/src/main/tts/systemTts.ts b/src/main/tts/systemTts.ts index 98e44c6..a09b59f 100644 --- a/src/main/tts/systemTts.ts +++ b/src/main/tts/systemTts.ts @@ -1190,7 +1190,23 @@ function speakWithPiper( }) } +/** + * 每轮播报结束时统一调用。之前只是把 currentProcess/currentPlayer 引用置空, + * 没有保证对应的系统进程真的退出——真机复测时发现合成卡死分支(见上面 + * "synth timeout" 处)只杀了 vitsWorker,没杀已经 spawn 出来、stdin 还开着 + * 干等数据的 aplay,这个进程会永远卡在那等一个再也不会来的 EOF,形成和 + * PLAYER_EXIT_TIMEOUT_MS 要解决的问题同一性质的泄漏,只是触发路径不同。 + * 与其在每个 done() 调用点各自记得去杀 currentPlayer,不如在 cleanup() + * 这个唯一的收尾出口统一兜底:无论从哪条路径走到这里,都先尝试杀掉还活着 + * 的进程,再清空引用。 + */ function cleanup(): void { + if (currentProcess) { + killWithEscalation(currentProcess) + } + if (currentPlayer) { + killWithEscalation(currentPlayer) + } currentProcess = null currentPlayer = null isSpeaking = false