mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Read aloud: Fix only first 32000 characters per chapter being read. Fixes #2086571 [Viewer TTS Skips Ahead](https://bugs.launchpad.net/calibre/+bug/2086571)
This commit is contained in:
parent
ebf8e8d72b
commit
0b2fe9d569
@ -15,6 +15,9 @@ if TYPE_CHECKING:
|
|||||||
from calibre.gui2.tts.types import TTSBackend
|
from calibre.gui2.tts.types import TTSBackend
|
||||||
|
|
||||||
|
|
||||||
|
MAX_UTTERANCE_LENGTH = 32 * 1024
|
||||||
|
|
||||||
|
|
||||||
class Utterance(NamedTuple):
|
class Utterance(NamedTuple):
|
||||||
text: str
|
text: str
|
||||||
index_in_positions: int
|
index_in_positions: int
|
||||||
@ -37,7 +40,7 @@ class Tracker:
|
|||||||
self.last_pos = 0
|
self.last_pos = 0
|
||||||
self.queue: deque[Utterance] = deque()
|
self.queue: deque[Utterance] = deque()
|
||||||
|
|
||||||
def parse_marked_text(self, marked_text, limit = 32 * 1024):
|
def parse_marked_text(self, marked_text, limit = MAX_UTTERANCE_LENGTH):
|
||||||
self.clear()
|
self.clear()
|
||||||
text = []
|
text = []
|
||||||
text_len = chunk_len = index_in_positions = offset_in_text = 0
|
text_len = chunk_len = index_in_positions = offset_in_text = 0
|
||||||
@ -63,9 +66,11 @@ class Tracker:
|
|||||||
self.marked_text = marked_text
|
self.marked_text = marked_text
|
||||||
return self.current_text()
|
return self.current_text()
|
||||||
|
|
||||||
def pop_first(self):
|
def pop_first(self) -> bool:
|
||||||
if self.queue:
|
if self.queue:
|
||||||
self.queue.popleft()
|
self.queue.popleft()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def current_text(self):
|
def current_text(self):
|
||||||
if self.queue:
|
if self.queue:
|
||||||
@ -244,6 +249,9 @@ class TTSManager(QObject):
|
|||||||
elif state is QTextToSpeech.State.Ready:
|
elif state is QTextToSpeech.State.Ready:
|
||||||
if prev_state in (QTextToSpeech.State.Paused, QTextToSpeech.State.Speaking):
|
if prev_state in (QTextToSpeech.State.Paused, QTextToSpeech.State.Speaking):
|
||||||
if not self.speaking_simple_text:
|
if not self.speaking_simple_text:
|
||||||
|
if self.tracker.pop_first() and (text := self.tracker.current_text()):
|
||||||
|
self.tts.say(text)
|
||||||
|
else:
|
||||||
self.emit_state_event('end')
|
self.emit_state_event('end')
|
||||||
elif state is QTextToSpeech.State.Error:
|
elif state is QTextToSpeech.State.Error:
|
||||||
self.emit_state_event('cancel')
|
self.emit_state_event('cancel')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user