From c2da702b0fa09cb278ebb3c62e5bc33c6f1b477a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 26 Oct 2024 12:26:17 +0530 Subject: [PATCH] Allow using the special voice name __skip__ to not vocalize text --- src/calibre/ebooks/oeb/polish/tts.py | 5 +++-- src/calibre/gui2/tweak_book/tts.py | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/tts.py b/src/calibre/ebooks/oeb/polish/tts.py index 01538be6a6..ef064ee4ba 100644 --- a/src/calibre/ebooks/oeb/polish/tts.py +++ b/src/calibre/ebooks/oeb/polish/tts.py @@ -61,6 +61,7 @@ ignored_tag_names = frozenset({ }) id_prefix = 'cttsw-' data_name = 'data-calibre-tts' +skip_name = '__skip__' def unmark_sentences_in_html(root): @@ -117,7 +118,7 @@ def mark_sentences_in_html(root, lang: str = '', voice: str = '') -> list[Senten self.pos = 0 for start, length in split_into_sentences_for_tts_embed(text, self.lang): stext = text[start:start+length] - if stext.strip(): + if stext.strip() and self.voice != '__skip__': elem_id = self.wrap_sentence(start, length) ans.append(Sentence(elem_id, stext, self.lang, self.voice)) if self.has_tail: @@ -127,7 +128,7 @@ def mark_sentences_in_html(root, lang: str = '', voice: str = '') -> list[Senten for start, length in split_into_sentences_for_tts_embed(self.elem.tail, self.parent_lang): end = start + length text = self.elem.tail[start:end] - if not text.strip(): + if not text.strip() or self.parent_voice == '__skip__': continue if before is None: before = self.elem.tail[:start] diff --git a/src/calibre/gui2/tweak_book/tts.py b/src/calibre/gui2/tweak_book/tts.py index a6946a040b..a772cd7905 100644 --- a/src/calibre/gui2/tweak_book/tts.py +++ b/src/calibre/gui2/tweak_book/tts.py @@ -17,6 +17,7 @@ from calibre.gui2.widgets import BusyCursor class EngineSettingsWidget(QWidget): def __init__(self, parent=None): + from calibre.ebooks.oeb.polish.tts import skip_name from calibre.gui2.tts.config import EmbeddingConfig super().__init__(parent) self.h = h = QHBoxLayout(self) @@ -33,13 +34,14 @@ audio overlays, such as the calibre viewer, will be able to hear the text read t

You can mark different passages to be spoken by different voices as shown in the example below: -

<p data-calibre-tts="{0}">This will be voiced by "{0}"</p>
-
<p data-calibre-tts="{1}">This will be voiced by "{1}"</p>
+
<p data-calibre-tts="{0}">This will be voiced by "{0}".</p>
+
<p data-calibre-tts="{1}">This will be voiced by "{1}".</p>
+
<p data-calibre-tts="{2}">This text will not be voiced at all.</p>

Note that generating the Text-to-speech audio will be quite slow, at the rate of approximately one sentence per couple of seconds, depending on your computer's hardware, so consider leave it running overnight. -''').format('cory', 'ryan')) +''').format('cory', 'ryan', skip_name)) self.save_settings = c.save_settings