Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
ensure volume restored after mic recording
Browse files Browse the repository at this point in the history
  • Loading branch information
krisgesling committed Jun 25, 2020
1 parent 4345011 commit 06c5b0d
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions mycroft/audio/audioservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,41 @@ def _restore_volume(self, message=None):
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:
self.bus.on('recognizer_loop:speech.recognition.unknown',
self.current.restore_volume()

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 for the messagem, 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):
Expand Down

0 comments on commit 06c5b0d

Please sign in to comment.