diff --git a/src/calibre/gui2/tts2/manager.py b/src/calibre/gui2/tts2/manager.py index 9e6863ebb0..4c14e20ca2 100644 --- a/src/calibre/gui2/tts2/manager.py +++ b/src/calibre/gui2/tts2/manager.py @@ -72,14 +72,14 @@ class Tracker: return self.queue[0].text return '' - def resume(self): + def resume(self, filler_char: str = ' '): self.last_pos = 0 if self.queue: self.last_pos = self.queue[0].index_in_positions if self.queue[0].reached_offset: o = self.queue[0].reached_offset # make sure positions remain the same for word tracking - self.queue[0] = self.queue[0]._replace(text=(' ' * o) + self.queue[0].text[o:]) + self.queue[0] = self.queue[0]._replace(text=(filler_char * o) + self.queue[0].text[o:]) return self.current_text() def boundary_reached(self, start): @@ -160,7 +160,7 @@ class TTSManager(QObject): yield rd if rd.is_speaking: if rd.needs_full_resume: - self.tts.say(self.tracker.resume()) + self.tts.say(self.tracker.resume(self.tts.filler_char)) else: self.tts.resume() diff --git a/src/calibre/gui2/tts2/piper.py b/src/calibre/gui2/tts2/piper.py index 58b67f922c..9c8f043efc 100644 --- a/src/calibre/gui2/tts2/piper.py +++ b/src/calibre/gui2/tts2/piper.py @@ -32,7 +32,7 @@ from qt.core import ( from calibre.constants import cache_dir, is_debugging from calibre.gui2 import error_dialog from calibre.gui2.tts2.types import EngineSpecificSettings, Quality, TTSBackend, Voice, piper_cmdline, widget_parent -from calibre.spell.break_iterator import split_into_sentences_for_tts +from calibre.spell.break_iterator import PARAGRAPH_SEPARATOR, split_into_sentences_for_tts from calibre.utils.localization import canonicalize_lang, get_lang from calibre.utils.resources import get_path as P @@ -156,6 +156,7 @@ def split_into_utterances(text: str, counter: count, lang: str = 'en'): class Piper(TTSBackend): engine_name: str = 'piper' + filler_char: str = PARAGRAPH_SEPARATOR _synthesis_done = pyqtSignal() def __init__(self, engine_name: str = '', parent: QObject|None = None): diff --git a/src/calibre/gui2/tts2/types.py b/src/calibre/gui2/tts2/types.py index 842df8cbd4..a5b44d53e8 100644 --- a/src/calibre/gui2/tts2/types.py +++ b/src/calibre/gui2/tts2/types.py @@ -269,6 +269,7 @@ class TTSBackend(QObject): available_voices: dict[str, tuple[Voice, ...]] = {} engine_name: str = '' default_output_module: str = '' + filler_char: str = ' ' def __init__(self, engine_name: str = '', parent: QObject|None = None): super().__init__(parent) diff --git a/src/calibre/spell/break_iterator.py b/src/calibre/spell/break_iterator.py index 503ae8ea3d..0926412a59 100644 --- a/src/calibre/spell/break_iterator.py +++ b/src/calibre/spell/break_iterator.py @@ -93,7 +93,10 @@ def split_long_sentences(sentence: str, offset: int, lang: str = 'en', limit: in yield offset + start_at, ' '.join(buf) -def split_into_sentences_for_tts(text: str, lang: str = 'en', PARAGRAPH_SEPARATOR: str = '\u2029'): +PARAGRAPH_SEPARATOR = '\u2029' + + +def split_into_sentences_for_tts(text: str, lang: str = 'en', PARAGRAPH_SEPARATOR: str = PARAGRAPH_SEPARATOR): import re def sub(m): return PARAGRAPH_SEPARATOR + ' ' * (len(m.group()) - 1)