From a8ab4676f511f71c881e880fc4c11eb4af910fc0 Mon Sep 17 00:00:00 2001 From: Satoshi Suzuki <35455415+mo29cg@users.noreply.github.com> Date: Sat, 7 Feb 2026 20:16:56 +0900 Subject: [PATCH] Fix deadlock when speech sequence contains no text When a language switch occurs mid-sequence, speak() may flush a textList containing only IndexCommands (no text strings) to wait_speak(). This causes two distinct deadlock scenarios: 1. OneCore/SAPI5 never fire synthDoneSpeaking for text-less sequences, so done.wait() blocks the BgThread forever. 2. HISS runs indexReached synchronously on the calling thread when there is no text to speak, which attempts to re-acquire self.lock already held by wait_speak(), causing a deadlock. The fix detects text-less sequences early in wait_speak(), fires the IndexCommand notifications directly, and returns before touching the lock or the engine. Fixes #32 Co-Authored-By: Claude Opus 4.6 --- addon/synthDrivers/UML.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addon/synthDrivers/UML.py b/addon/synthDrivers/UML.py index 74a1db5..e609e94 100644 --- a/addon/synthDrivers/UML.py +++ b/addon/synthDrivers/UML.py @@ -193,6 +193,20 @@ def speak(self, seq): _execWhenDone(self.notify_done) def wait_speak(self, synth, seq): + # If seq contains no text (e.g. only IndexCommands from a language switch + # boundary), skip the engine entirely and fire index notifications directly. + # Without this, two deadlocks can occur: + # 1. Some engines (OneCore, SAPI5) never fire synthDoneSpeaking for + # text-less sequences, so done.wait() blocks forever. + # 2. HISS may run indexReached synchronously on the calling thread when + # there is no text, which re-enters self.lock and deadlocks. + if not any(isinstance(item, str) for item in seq): + for item in seq: + if isinstance(item, IndexCommand): + synthDriverHandler.synthIndexReached.notify( + synth=self, index=item.index + ) + return with self.lock: self.done.clear() self.cur_synth = synth