Allow using the special voice name __skip__ to not vocalize text

This commit is contained in:
Kovid Goyal 2024-10-26 12:26:17 +05:30
parent 358a202268
commit c2da702b0f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 5 deletions

View File

@ -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]

View File

@ -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
<p>You can mark different passages to be spoken by different voices as shown in the example below:
<div><code>&lt;p data-calibre-tts="{0}"&gt;This will be voiced by "{0}"&lt;/p&gt;</code></div>
<div><code>&lt;p data-calibre-tts="{1}"&gt;This will be voiced by "{1}"&lt;/p&gt;</code></div>
<div><code>&lt;p data-calibre-tts="{0}"&gt;This will be voiced by "{0}".&lt;/p&gt;</code></div>
<div><code>&lt;p data-calibre-tts="{1}"&gt;This will be voiced by "{1}".&lt;/p&gt;</code></div>
<div><code>&lt;p data-calibre-tts="{2}"&gt;This text will not be voiced at all.&lt;/p&gt;</code></div>
<p style="font-size: small">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