Dont block UI while waiting for speech to start

This commit is contained in:
Kovid Goyal 2023-02-01 22:39:53 +05:30
parent 0b9d30a725
commit f64b9e3e2c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 15 additions and 7 deletions

View File

@ -76,7 +76,13 @@ class Client:
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()
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):
raise x.as_exception(check_for_no_audio_devices=True)
else:

View File

@ -57,9 +57,11 @@ class TTS(QObject):
def dispatch_on_main_thread(self, func):
try:
func()
except Exception:
except Exception as e:
import traceback
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
def tts_client_class(self):

View File

@ -121,8 +121,8 @@ class Error(NamedTuple):
def as_exception(self, msg='', check_for_no_audio_devices=False):
if check_for_no_audio_devices and self.hr == 0xc00d36fa:
raise NoAudioDevices()
raise SpeechError(self, msg)
return NoAudioDevices()
return SpeechError(self, msg)
class Synthesizing(NamedTuple):
@ -396,9 +396,7 @@ class WinSpeech:
st = 'cued' if is_cued else ('ssml' if is_xml else 'text')
sz = encode_to_file_object(text, shm)
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)
if x.state is MediaState.failed:
raise x.as_exception()
self.wait_for('speech synthesis to start', Synthesizing, related_to=self.current_speak_cmd_id, timeout=8)
return self.current_speak_cmd_id
def dispatch_message(self, x):

View File

@ -243,6 +243,8 @@ class ReadAloud:
self.play()
if data is not None:
pass
elif which is 'cancel':
self.state = STOPPED
def send_message(self, type, **kw):
self.view.iframe_wrapper.send_message('tts', type=type, **kw)