Windows: Read Aloud: Fix an occasional crash when stopping read aloud when using the legacy windows TTS backend. Fixes #2080705 [Download read aloud api failed](https://bugs.launchpad.net/calibre/+bug/2080705)

This commit is contained in:
Kovid Goyal 2024-09-26 12:06:11 +05:30
parent c07c662a5a
commit df7344be33
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -38,7 +38,17 @@ class QtTTSBackend(TTSBackend):
self.tts.resume()
def stop(self) -> None:
self.tts.stop()
if self.tts.engine() == 'sapi' and self.tts.state() is QTextToSpeech.State.Speaking:
# prevent an occasional crash on stop by re-creating the engine rather than stopping it
self.tts.sayingWord.disconnect()
self.tts.stateChanged.disconnect()
self.tts.pause()
self.tts.deleteLater()
del self.tts
self._qt_reload_after_configure('sapi')
self._state_changed(QTextToSpeech.State.Ready)
else:
self.tts.stop()
def say(self, text: str) -> None:
self.last_word_offset = 0