From 4799bd0b3146b46f812f9258c34cd2f19087738e Mon Sep 17 00:00:00 2001 From: Kris Gesling Date: Mon, 29 Jun 2020 14:06:30 +0930 Subject: [PATCH] minor cleanup for PR review --- mycroft/audio/audioservice.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mycroft/audio/audioservice.py b/mycroft/audio/audioservice.py index 36a3e5cd2d3a..9c751e425751 100644 --- a/mycroft/audio/audioservice.py +++ b/mycroft/audio/audioservice.py @@ -304,36 +304,37 @@ def _restore_volume_after_record(self, message=None): Args: message: message bus message, not used but required """ - def __restore_volume(): + def restore_volume(): LOG.debug('restoring volume') self.current.restore_volume() - def wait_for_speak(bus, timeout=8): + def wait_for_speak(timeout=8): """Wait for a speak Message on the bus. Arguments: bus (Mycroft MessageBus): Bus instance to listen on timeout (int): how long to wait, defaults to 8 sec """ - self.speak_msg_detected = False + speak_msg_detected = False def detected_speak(message=None): - self.speak_msg_detected = True + nonlocal speak_msg_detected + speak_msg_detected = True self.bus.on('speak', detected_speak) time.sleep(timeout) self.bus.remove('speak', detected_speak) - return self.speak_msg_detected + return speak_msg_detected - if self.current is None: - LOG.debug("No audio service to restore volume of") - return None - self.bus.on('recognizer_loop:speech.recognition.unknown', - __restore_volume) - speak_msg_detected = wait_for_speak(self.bus) - if not speak_msg_detected: - __restore_volume() - self.bus.remove('recognizer_loop:speech.recognition.unknown', + if self.current: + self.bus.on('recognizer_loop:speech.recognition.unknown', __restore_volume) + speak_msg_detected = wait_for_speak(self.bus) + if not speak_msg_detected: + __restore_volume() + self.bus.remove('recognizer_loop:speech.recognition.unknown', + __restore_volume) + else: + LOG.debug("No audio service to restore volume of") def play(self, tracks, prefered_service, repeat=False): """