From 8b65afb37d6b8e36759d878f52a3fa228e84bde6 Mon Sep 17 00:00:00 2001 From: jarbasal Date: Wed, 3 Oct 2018 13:11:24 +0100 Subject: [PATCH] pep8 --- mycroft/audio/speech.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/mycroft/audio/speech.py b/mycroft/audio/speech.py index 52aa0d266161..bdb13c501938 100644 --- a/mycroft/audio/speech.py +++ b/mycroft/audio/speech.py @@ -23,6 +23,7 @@ from mycroft.util.log import LOG from mycroft.messagebus.message import Message +speak_muted = False bus = None # Mycroft messagebus connection config = None tts = None @@ -39,6 +40,25 @@ def _start_listener(message): create_signal('startListening') +def handle_unmute_tts(event): + """ enable tts execution """ + global speak_muted + speak_muted = False + bus.emit(Message("mycroft.tts.mute_status", {"muted": speak_muted})) + + +def handle_mute_tts(event): + """ disable tts execution """ + global speak_muted + speak_muted = True + bus.emit(Message("mycroft.tts.mute_status", {"muted": speak_muted})) + + +def handle_mute_status(event): + """ emit tts mute status to bus """ + bus.emit(Message("mycroft.tts.mute_status", {"muted": speak_muted})) + + def handle_speak(event): """ Handle "speak" message @@ -115,10 +135,11 @@ def mute_and_speak(utterance, ident): tts_hash = hash(str(config.get('tts', ''))) LOG.info("Speak: " + utterance) - try: - tts.execute(utterance, ident) - except Exception as e: - LOG.error('TTS execution failed ({})'.format(repr(e))) + if not speak_muted: + try: + tts.execute(utterance, ident) + except Exception as e: + LOG.error('TTS execution failed ({})'.format(repr(e))) def handle_stop(event): @@ -153,6 +174,10 @@ def init(messagebus): bus.on('speak', handle_speak) bus.on('mycroft.mic.listen', _start_listener) + bus.on('mycroft.tts.mute', handle_mute_tts) + bus.on('mycroft.tts.unmute', handle_unmute_tts) + bus.on('mycroft.tts.mute_status.request', handle_mute_status) + tts = TTSFactory.create() tts.init(bus) tts_hash = config.get('tts')