From 92ebb83ed8d9e7c80daf4b41fefa7b96b7c2051a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 Nov 2020 13:54:26 +0530 Subject: [PATCH] Ignore errors in tts callbacks --- src/calibre/gui2/tts/linux.py | 6 +++++- src/calibre/gui2/tts/macos.py | 6 +++++- src/calibre/gui2/tts/windows.py | 9 ++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tts/linux.py b/src/calibre/gui2/tts/linux.py index 3af203ed27..53101a6f58 100644 --- a/src/calibre/gui2/tts/linux.py +++ b/src/calibre/gui2/tts/linux.py @@ -88,7 +88,11 @@ class Client: self.update_status(callback_type, index_mark) event = self.msg_as_event(callback_type, index_mark) if event is not None: - callback(event) + try: + callback(event) + except Exception: + import traceback + traceback.print_exc() def cw(callback_type, index_mark=None): self.dispatch_on_main_thread(partial(callback_wrapper, callback_type, index_mark)) diff --git a/src/calibre/gui2/tts/macos.py b/src/calibre/gui2/tts/macos.py index c637b1269f..3f232b32c0 100644 --- a/src/calibre/gui2/tts/macos.py +++ b/src/calibre/gui2/tts/macos.py @@ -32,7 +32,11 @@ class Client: else: return if self.current_callback is not None: - self.current_callback(event) + try: + self.current_callback(event) + except Exception: + import traceback + traceback.print_exc() def speak_simple_text(self, text): self.current_callback = None diff --git a/src/calibre/gui2/tts/windows.py b/src/calibre/gui2/tts/windows.py index 2d3f54d8f7..9506931527 100644 --- a/src/calibre/gui2/tts/windows.py +++ b/src/calibre/gui2/tts/windows.py @@ -26,6 +26,7 @@ class Client: self.current_stream_number = None self.current_callback = None self.dispatch_on_main_thread = dispatch_on_main_thread + self.status = {'synthesizing': False, 'paused': False} def __del__(self): if self.sp_voice is not None: @@ -50,12 +51,18 @@ class Client: event = Event(EventType.mark, event_data) elif event_type == SPEI_START_INPUT_STREAM: event = Event(EventType.begin) + self.status = {'synthesizing': True, 'paused': False} elif event_type == SPEI_END_INPUT_STREAM: event = Event(EventType.end) + self.status = {'synthesizing': False, 'paused': False} else: continue if c is not None and stream_number == self.current_stream_number: - c(event) + try: + c(event) + except Exception: + import traceback + traceback.print_exc() def speak_simple_text(self, text): from calibre_extensions.winsapi import (