-
Notifications
You must be signed in to change notification settings - Fork 1.3k
prevent audio playing between mic record and utt handling #2621
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,7 +190,8 @@ def load_services_callback(self): | |
self.bus.on('recognizer_loop:audio_output_start', self._lower_volume) | ||
self.bus.on('recognizer_loop:record_begin', self._lower_volume) | ||
self.bus.on('recognizer_loop:audio_output_end', self._restore_volume) | ||
self.bus.on('recognizer_loop:record_end', self._restore_volume) | ||
self.bus.on('recognizer_loop:record_end', | ||
self._restore_volume_after_record) | ||
|
||
def track_start(self, track): | ||
"""Callback method called from the services to indicate start of | ||
|
@@ -294,6 +295,46 @@ def _restore_volume(self, message=None): | |
if not self.volume_is_low: | ||
self.current.restore_volume() | ||
|
||
def _restore_volume_after_record(self, message=None): | ||
""" | ||
Restores the volume when Mycroft is done recording. | ||
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.current.restore_volume() | ||
|
||
def wait_for_speak(bus, timeout=8): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"""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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like this can be a local variable instead of an object variable to keep things encapsulated. and in feels like otherwise there could be issues with re-entrancy. |
||
|
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably a personal opinion but perhaps invert this logic for clarity 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") |
||
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): | ||
""" | ||
play starts playing the audio on the prefered service if it | ||
|
@@ -440,4 +481,5 @@ def shutdown(self): | |
self.bus.remove('recognizer_loop:record_begin', self._lower_volume) | ||
self.bus.remove('recognizer_loop:audio_output_end', | ||
self._restore_volume) | ||
self.bus.remove('recognizer_loop:record_end', self._restore_volume) | ||
self.bus.remove('recognizer_loop:record_end', | ||
self._restore_volume_after_record) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need the
__
it's local so it won't need to be made anonymous?