mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Fix position tracking on reload in piper backed
This commit is contained in:
parent
36d9b620c6
commit
1175711d54
@ -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()
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user