ensure volume restored after mic recording
@@ -298,23 +298,42 @@ class AudioService:
def _restore_volume_after_record(self, message=None):
"""
Restores the volume when Mycroft is done recording.
- If no utterance detected, restores immediately.
- Else keeps volume low until Mycroft responds to the utterance.
+ If no utterance detected, restore immediately.
+ If no response is made in reasonable time, then also restore.
Args:
message: message bus message, not used but required
"""
def __restore_volume():
LOG.debug('restoring volume')
- self.volume_is_low = False
- if not self.volume_is_low:
self.current.restore_volume()
- self.bus.remove('recognizer_loop:speech.recognition.unknown',
- __restore_volume)
- if self.current:
+ def wait_for_speak(bus, 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
+
+ def detected_speak(message=None):
+ self.speak_msg_detected = True
+ self.bus.on('speak', detected_speak)
+ time.sleep(timeout)
+ self.bus.remove('speak', detected_speak)
+ return self.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',
+ __restore_volume)
def play(self, tracks, prefered_service, repeat=False):
"""
