mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -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 self.queue[0].text
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def resume(self):
|
def resume(self, filler_char: str = ' '):
|
||||||
self.last_pos = 0
|
self.last_pos = 0
|
||||||
if self.queue:
|
if self.queue:
|
||||||
self.last_pos = self.queue[0].index_in_positions
|
self.last_pos = self.queue[0].index_in_positions
|
||||||
if self.queue[0].reached_offset:
|
if self.queue[0].reached_offset:
|
||||||
o = self.queue[0].reached_offset
|
o = self.queue[0].reached_offset
|
||||||
# make sure positions remain the same for word tracking
|
# 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()
|
return self.current_text()
|
||||||
|
|
||||||
def boundary_reached(self, start):
|
def boundary_reached(self, start):
|
||||||
@ -160,7 +160,7 @@ class TTSManager(QObject):
|
|||||||
yield rd
|
yield rd
|
||||||
if rd.is_speaking:
|
if rd.is_speaking:
|
||||||
if rd.needs_full_resume:
|
if rd.needs_full_resume:
|
||||||
self.tts.say(self.tracker.resume())
|
self.tts.say(self.tracker.resume(self.tts.filler_char))
|
||||||
else:
|
else:
|
||||||
self.tts.resume()
|
self.tts.resume()
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ from qt.core import (
|
|||||||
from calibre.constants import cache_dir, is_debugging
|
from calibre.constants import cache_dir, is_debugging
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.tts2.types import EngineSpecificSettings, Quality, TTSBackend, Voice, piper_cmdline, widget_parent
|
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.localization import canonicalize_lang, get_lang
|
||||||
from calibre.utils.resources import get_path as P
|
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):
|
class Piper(TTSBackend):
|
||||||
|
|
||||||
engine_name: str = 'piper'
|
engine_name: str = 'piper'
|
||||||
|
filler_char: str = PARAGRAPH_SEPARATOR
|
||||||
_synthesis_done = pyqtSignal()
|
_synthesis_done = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, engine_name: str = '', parent: QObject|None = None):
|
def __init__(self, engine_name: str = '', parent: QObject|None = None):
|
||||||
|
@ -269,6 +269,7 @@ class TTSBackend(QObject):
|
|||||||
available_voices: dict[str, tuple[Voice, ...]] = {}
|
available_voices: dict[str, tuple[Voice, ...]] = {}
|
||||||
engine_name: str = ''
|
engine_name: str = ''
|
||||||
default_output_module: str = ''
|
default_output_module: str = ''
|
||||||
|
filler_char: str = ' '
|
||||||
|
|
||||||
def __init__(self, engine_name: str = '', parent: QObject|None = None):
|
def __init__(self, engine_name: str = '', parent: QObject|None = None):
|
||||||
super().__init__(parent)
|
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)
|
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
|
import re
|
||||||
def sub(m):
|
def sub(m):
|
||||||
return PARAGRAPH_SEPARATOR + ' ' * (len(m.group()) - 1)
|
return PARAGRAPH_SEPARATOR + ' ' * (len(m.group()) - 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user