Skip to content

Commit

Permalink
Read aloud: Fix reading large numeric words causing text synchronizat…
Browse files Browse the repository at this point in the history
…ion to fail when using some legacy TTS engines. Fixes #2080708 [Private bug](https://bugs.launchpad.net/calibre/+bug/2080708)
  • Loading branch information
kovidgoyal committed Sep 26, 2024
1 parent 035a3fc commit f7c4d8c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/calibre/gui2/tts/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, engine_name: str = '', parent: QObject|None = None):
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, ...]]:
Expand All @@ -40,6 +41,7 @@ def stop(self) -> None:

def say(self, text: str) -> None:
self.last_word_offset = 0
self.last_spoken_word = None
self.speaking_text = text
self.tts.say(text)

Expand Down Expand Up @@ -96,6 +98,11 @@ def _qt_reload_after_configure(self, engine_name: str) -> None:
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))
Expand Down

0 comments on commit f7c4d8c

Please sign in to comment.