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

Commit

Permalink
prevent audio playing between mic record and handling
Browse files Browse the repository at this point in the history
  • Loading branch information
krisgesling committed Jun 19, 2020
1 parent 819ea94 commit 4345011
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions mycroft/audio/audioservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -294,6 +295,27 @@ 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, restores immediately.
Else keeps volume low until Mycroft responds to the utterance.
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',
__restore_volume)

def play(self, tracks, prefered_service, repeat=False):
"""
play starts playing the audio on the prefered service if it
Expand Down Expand Up @@ -440,4 +462,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)

0 comments on commit 4345011

Please sign in to comment.