Skip to content

Commit 600e9cd

Browse files
committed
Fix TTS narration removal not working
1 parent a855923 commit 600e9cd

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

  • src/calibre/ebooks/oeb/polish

src/calibre/ebooks/oeb/polish/tts.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Chunk(NamedTuple):
6060
'img', 'object', 'script', 'style', 'head', 'title', 'form', 'input', 'br', 'hr', 'map', 'textarea', 'svg', 'math', 'rp', 'rt', 'rtc',
6161
})
6262
id_prefix = 'cttsw-'
63+
data_name = 'data-calibre-tts'
6364

6465

6566
def unmark_sentences_in_html(root):
@@ -85,7 +86,7 @@ def __init__(self, elem, tag_name, parent_lang, parent_voice, child_lang=''):
8586
self.lang = child_lang or lang_for_elem(elem, parent_lang)
8687
self.parent_lang = parent_lang
8788
self.parent_voice = parent_voice
88-
q = elem.get('data-calibre-tts', '')
89+
q = elem.get(data_name, '')
8990
self.voice = parent_voice
9091
if q.startswith('{'): # }
9192
with suppress(Exception):
@@ -350,7 +351,7 @@ def wrap_sentence(self, start: int, length: int) -> str:
350351
simple_allowed = True
351352
children_to_process = []
352353
for child in p.children:
353-
child_voice = child.get('data-calibre-tts', '')
354+
child_voice = child.get(data_name, '')
354355
child_lang = lang_for_elem(child, p.lang)
355356
child_tag_name = barename(child.tag).lower() if isinstance(child.tag, str) else ''
356357
if simple_allowed and child_lang == p.lang and child_voice == p.voice and child_tag_name in continued_tag_names and len(child) == 0:
@@ -429,17 +430,18 @@ def remove_embedded_tts(container):
429430
unmark_sentences_in_html(root)
430431
container.dirty(name)
431432
smil_item = id_map.get(smil_id)
432-
if smil_item:
433+
if smil_item is not None:
433434
smil_href = smil_item.get('href')
434435
if smil_href:
435-
smil_name = container.href_to_name(smil_item.get('href'))
436+
smil_name = container.href_to_name(smil_item.get('href'), container.opf_name)
436437
smil_root = container.parsed(smil_name)
437-
for ahref in smil_root.xpath('//@src'):
438+
for ahref in smil_root.xpath('//*[local-name() = "audio"]/@src'):
438439
aname = container.href_to_name(ahref, smil_name)
439440
media_files.add(aname)
440441
container.remove_from_xml(smil_item)
441442
for aname in media_files:
442443
container.remove_item(aname)
444+
container.dirty(container.opf_name)
443445

444446

445447
def embed_tts(container, report_progress=None, callback_to_download_voices=None):

0 commit comments

Comments
 (0)