minor cleanup for PR review
@@ -304,36 +304,37 @@ class AudioService:
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
+ if self.current:
self.bus.on('recognizer_loop:speech.recognition.unknown',
- __restore_volume)
+ restore_volume)
speak_msg_detected = wait_for_speak(self.bus)
if not speak_msg_detected:
- __restore_volume()
+ restore_volume()
self.bus.remove('recognizer_loop:speech.recognition.unknown',
- __restore_volume)
+ restore_volume)
+ else:
+ LOG.debug("No audio service to restore volume of")
def play(self, tracks, prefered_service, repeat=False):
"""
