mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont block UI while waiting for speech to start
This commit is contained in:
parent
0b9d30a725
commit
f64b9e3e2c
@ -76,7 +76,13 @@ class Client:
|
|||||||
self.current_chunk_idx += 1
|
self.current_chunk_idx += 1
|
||||||
self.backend.speak(self.current_chunks[self.current_chunk_idx], is_cued=True)
|
self.backend.speak(self.current_chunks[self.current_chunk_idx], is_cued=True)
|
||||||
elif x.state is MediaState.failed:
|
elif x.state is MediaState.failed:
|
||||||
raise x.as_exception()
|
self.clear_chunks()
|
||||||
|
self.callback_ignoring_errors(Event(EventType.cancel))
|
||||||
|
e = x.as_exception()
|
||||||
|
e.display_to_user = True
|
||||||
|
raise e
|
||||||
|
elif x.state is MediaState.opened:
|
||||||
|
self.callback_ignoring_errors(Event(EventType.begin))
|
||||||
elif isinstance(x, Error):
|
elif isinstance(x, Error):
|
||||||
raise x.as_exception(check_for_no_audio_devices=True)
|
raise x.as_exception(check_for_no_audio_devices=True)
|
||||||
else:
|
else:
|
||||||
|
@ -57,9 +57,11 @@ class TTS(QObject):
|
|||||||
def dispatch_on_main_thread(self, func):
|
def dispatch_on_main_thread(self, func):
|
||||||
try:
|
try:
|
||||||
func()
|
func()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
if getattr(e, 'display_to_user', False):
|
||||||
|
error_dialog(self.parent(), _('Error in speech subsystem'), str(e), det_msg=traceback.format_exc(), show=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tts_client_class(self):
|
def tts_client_class(self):
|
||||||
|
@ -121,8 +121,8 @@ class Error(NamedTuple):
|
|||||||
|
|
||||||
def as_exception(self, msg='', check_for_no_audio_devices=False):
|
def as_exception(self, msg='', check_for_no_audio_devices=False):
|
||||||
if check_for_no_audio_devices and self.hr == 0xc00d36fa:
|
if check_for_no_audio_devices and self.hr == 0xc00d36fa:
|
||||||
raise NoAudioDevices()
|
return NoAudioDevices()
|
||||||
raise SpeechError(self, msg)
|
return SpeechError(self, msg)
|
||||||
|
|
||||||
|
|
||||||
class Synthesizing(NamedTuple):
|
class Synthesizing(NamedTuple):
|
||||||
@ -396,9 +396,7 @@ class WinSpeech:
|
|||||||
st = 'cued' if is_cued else ('ssml' if is_xml else 'text')
|
st = 'cued' if is_cued else ('ssml' if is_xml else 'text')
|
||||||
sz = encode_to_file_object(text, shm)
|
sz = encode_to_file_object(text, shm)
|
||||||
self.current_speak_cmd_id = self.send_command(f'speak {st} shm {sz} {shm.name}')
|
self.current_speak_cmd_id = self.send_command(f'speak {st} shm {sz} {shm.name}')
|
||||||
x = self.wait_for('speech synthesis to start', MediaStateChanged, related_to=self.current_speak_cmd_id, timeout=8)
|
self.wait_for('speech synthesis to start', Synthesizing, related_to=self.current_speak_cmd_id, timeout=8)
|
||||||
if x.state is MediaState.failed:
|
|
||||||
raise x.as_exception()
|
|
||||||
return self.current_speak_cmd_id
|
return self.current_speak_cmd_id
|
||||||
|
|
||||||
def dispatch_message(self, x):
|
def dispatch_message(self, x):
|
||||||
|
@ -243,6 +243,8 @@ class ReadAloud:
|
|||||||
self.play()
|
self.play()
|
||||||
if data is not None:
|
if data is not None:
|
||||||
pass
|
pass
|
||||||
|
elif which is 'cancel':
|
||||||
|
self.state = STOPPED
|
||||||
|
|
||||||
def send_message(self, type, **kw):
|
def send_message(self, type, **kw):
|
||||||
self.view.iframe_wrapper.send_message('tts', type=type, **kw)
|
self.view.iframe_wrapper.send_message('tts', type=type, **kw)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user