Hopefully fixed a weird speech bug where some games could make it suddenly stop speaking.
This commit is contained in:
@@ -201,16 +201,38 @@ class SpeechServer(speechserver.SpeechServer):
|
||||
mode = self._PUNCTUATION_MODE_MAP[settings.verbalizePunctuationStyle]
|
||||
self._client.set_punctuation(mode)
|
||||
|
||||
def _send_command(self, command, *args, **kwargs):
|
||||
try:
|
||||
return command(*args, **kwargs)
|
||||
except speechd.SSIPCommunicationError:
|
||||
msg = "SPEECH DISPATCHER: Connection lost. Trying to reconnect."
|
||||
debug.printMessage(debug.LEVEL_INFO, msg, True)
|
||||
self.reset()
|
||||
return command(*args, **kwargs)
|
||||
except Exception:
|
||||
pass
|
||||
def _log_command_failure(self, command_name, error, will_retry=False):
|
||||
error_type = type(error).__name__
|
||||
action = " Resetting backend and retrying." if will_retry else ""
|
||||
msg = f"SPEECH DISPATCHER: {command_name} failed with {error_type}: {error!s}.{action}"
|
||||
debug.printMessage(debug.LEVEL_WARNING, msg, True)
|
||||
|
||||
def _send_command(self, command, *args, treat_none_as_error=False, **kwargs):
|
||||
command_name = getattr(command, "__name__", repr(command))
|
||||
|
||||
for attempt in range(2):
|
||||
try:
|
||||
result = command(*args, **kwargs)
|
||||
if treat_none_as_error and result is None:
|
||||
raise RuntimeError(f"{command_name} returned None")
|
||||
return result
|
||||
except speechd.SSIPCommunicationError as error:
|
||||
self._log_command_failure(command_name, error, will_retry=attempt == 0)
|
||||
except speechd.SSIPCommandError as error:
|
||||
self._log_command_failure(command_name, error, will_retry=attempt == 0)
|
||||
except RuntimeError as error:
|
||||
if not treat_none_as_error:
|
||||
raise
|
||||
self._log_command_failure(command_name, error, will_retry=attempt == 0)
|
||||
except Exception as error:
|
||||
self._log_command_failure(command_name, error, will_retry=False)
|
||||
return None
|
||||
|
||||
if attempt == 0:
|
||||
self.reset()
|
||||
continue
|
||||
|
||||
return None
|
||||
|
||||
def _set_rate(self, acss_rate):
|
||||
rate = int(2 * max(0, min(99, acss_rate)) - 98)
|
||||
@@ -267,10 +289,10 @@ class SpeechServer(speechserver.SpeechServer):
|
||||
return
|
||||
|
||||
try:
|
||||
sd_rate = self._send_command(self._client.get_rate)
|
||||
sd_pitch = self._send_command(self._client.get_pitch)
|
||||
sd_volume = self._send_command(self._client.get_volume)
|
||||
sd_language = self._send_command(self._client.get_language)
|
||||
sd_rate = self._send_command(self._client.get_rate, treat_none_as_error=True)
|
||||
sd_pitch = self._send_command(self._client.get_pitch, treat_none_as_error=True)
|
||||
sd_volume = self._send_command(self._client.get_volume, treat_none_as_error=True)
|
||||
sd_language = self._send_command(self._client.get_language, treat_none_as_error=True)
|
||||
except Exception:
|
||||
sd_rate = sd_pitch = sd_volume = sd_language = "(exception occurred)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user