Fix lock around speech.
the lock could be taken by a waiting thread between sentences in a multi-sentenced utterance. This locking method will allow the entire utterance to be synthezised before handling next.
@@ -45,6 +45,7 @@ def handle_speak(event):
Configuration.init(ws)
global _last_stop_signal
+ with lock:
# Mild abuse of the signal system to allow other processes to detect
# when TTS is happening. See mycroft.util.is_speaking()
@@ -73,7 +74,8 @@ def handle_speak(event):
raise
except:
LOG.error('Error in mute_and_speak', exc_info=True)
- if _last_stop_signal > start or check_for_signal('buttonPress'):
+ if (_last_stop_signal > start or
+ check_for_signal('buttonPress')):
break
else:
mute_and_speak(utterance)
@@ -88,7 +90,6 @@ def mute_and_speak(utterance):
"""
global tts_hash
- lock.acquire()
# update TTS object if configuration has changed
if tts_hash != hash(str(config.get('tts', ''))):
global tts
@@ -101,10 +102,7 @@ def mute_and_speak(utterance):
tts_hash = hash(str(config.get('tts', '')))
LOG.info("Speak: " + utterance)
- try:
tts.execute(utterance)
- finally:
- lock.release()
def handle_stop(event):
