Read aloud: Fix reading large numeric words causing text synchronization to fail when using some legacy TTS engines. Fixes #2080708 [Private bug](https://bugs.launchpad.net/calibre/+bug/2080708)

This commit is contained in:
Kovid Goyal 2024-09-26 10:11:40 +05:30
parent 035a3fcb2d
commit f7c4d8c02c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -14,6 +14,7 @@ class QtTTSBackend(TTSBackend):
self.speaking_text = ''
self.last_word_offset = 0
self._qt_reload_after_configure(engine_name)
self.last_spoken_word = None
@property
def available_voices(self) -> dict[str, tuple[Voice, ...]]:
@ -40,6 +41,7 @@ class QtTTSBackend(TTSBackend):
def say(self, text: str) -> None:
self.last_word_offset = 0
self.last_spoken_word = None
self.speaking_text = text
self.tts.say(text)
@ -96,6 +98,11 @@ class QtTTSBackend(TTSBackend):
def _saying_word(self, word: str, utterance_id: int, start: int, length: int) -> None:
# Qt's word tracking is broken with non-BMP unicode chars, the
# start and length values are totally wrong, so track manually
# print(f'{repr(word)=} {idx=} {start=} {length=}, {repr(self.speaking_text[start:start+length])=}')
key = word, start, length
if self.last_spoken_word == key:
return
self.last_spoken_word = key
idx = self.speaking_text.find(word, self.last_word_offset)
if idx > -1:
self.saying.emit(idx, len(word))