mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Basic speech seems to work
This commit is contained in:
parent
78d890c925
commit
eef892a90f
@ -51,6 +51,7 @@ class Client:
|
||||
self.dispatch_on_main_thread = dispatch_on_main_thread
|
||||
self.synthesizing = False
|
||||
self.settings = settings or {}
|
||||
self.clear_chunks()
|
||||
self.apply_settings()
|
||||
|
||||
def __del__(self):
|
||||
@ -63,19 +64,17 @@ class Client:
|
||||
self.dispatch_on_main_thread(partial(self.handle_event, msg))
|
||||
|
||||
def handle_event(self, x):
|
||||
if isinstance(x, MarkReached):
|
||||
if isinstance(x, MarkReached) and self.current_chunks:
|
||||
self.last_mark = x.id
|
||||
self.callback_ignoring_errors(Event(EventType.mark, x.id))
|
||||
elif isinstance(x, MediaStateChanged) and self.current_chunks:
|
||||
if x.state is MediaState.opened:
|
||||
if self.current_chunk == 0:
|
||||
self.callback_ignoring_errors(Event(EventType.begin))
|
||||
elif x.state is MediaState.ended:
|
||||
if self.current_chunk >= len(self.chunks) - 1:
|
||||
if x.state is MediaState.ended:
|
||||
if self.current_chunk_idx >= len(self.current_chunks) - 1:
|
||||
self.clear_chunks()
|
||||
self.callback_ignoring_errors(Event(EventType.end))
|
||||
else:
|
||||
self.current_chunk += 1
|
||||
self.backend.speak(self.chunks[self.current_chunk], is_cued=True)
|
||||
self.current_chunk_idx += 1
|
||||
self.backend.speak(self.current_chunks[self.current_chunk_idx], is_cued=True)
|
||||
elif x.state is MediaState.failed:
|
||||
raise x.as_exception()
|
||||
elif isinstance(x, Error):
|
||||
@ -92,11 +91,13 @@ class Client:
|
||||
self.backend.pause()
|
||||
self.clear_chunks()
|
||||
self.current_callback = callback
|
||||
self.chunks = tuple(split_into_chunks(text, self.chunk_size))
|
||||
self.current_chunk = 0
|
||||
if self.chunks:
|
||||
self.backend.speak(self.chunks[self.current_chunk], is_cued=True)
|
||||
self.current_chunks = tuple(split_into_chunks(text, self.chunk_size))
|
||||
self.current_chunk_idx = 0
|
||||
if self.current_chunks:
|
||||
self.backend.speak(self.current_chunks[self.current_chunk_idx], is_cued=True)
|
||||
self.synthesizing = True
|
||||
if self.current_callback is not None:
|
||||
self.current_callback(Event(EventType.begin))
|
||||
|
||||
def callback_ignoring_errors(self, ev):
|
||||
if self.current_callback is not None:
|
||||
@ -108,7 +109,7 @@ class Client:
|
||||
|
||||
def clear_chunks(self):
|
||||
self.synthesizing = False
|
||||
self.current_chunk = 0
|
||||
self.current_chunk_idx = -100
|
||||
self.current_chunks = []
|
||||
self.last_mark = -1
|
||||
|
||||
|
@ -107,7 +107,8 @@ class SpeechError(OSError):
|
||||
|
||||
class NoAudioDevices(Exception):
|
||||
def __init__(self):
|
||||
super().__init__(_('No active audio output devices found. Connect headphones or speakers.'))
|
||||
super().__init__(_('No active audio output devices found.'
|
||||
' Connect headphones or speakers. If you are using Remote Desktop then enable Remote Audio for it.'))
|
||||
|
||||
|
||||
class Error(NamedTuple):
|
||||
@ -119,8 +120,8 @@ class Error(NamedTuple):
|
||||
related_to: int = 0
|
||||
|
||||
def as_exception(self, msg='', check_for_no_audio_devices=False):
|
||||
if check_for_no_audio_devices and self.hr == 0x8004503a:
|
||||
raise NoAudioDevices(_('No active audio output devices found. Connect headphones or speakers.'))
|
||||
if check_for_no_audio_devices and self.hr == 0xc00d36fa:
|
||||
raise NoAudioDevices()
|
||||
raise SpeechError(self, msg)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user