From d9c31bfaf0d247095685da8031783e787c634a9f Mon Sep 17 00:00:00 2001 From: emphasize Date: Wed, 8 Nov 2023 17:16:06 +0100 Subject: [PATCH] audio service ducking --- ovos_audio/playback.py | 4 ++++ ovos_audio/service.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ovos_audio/playback.py b/ovos_audio/playback.py index a47e57a..1fff082 100644 --- a/ovos_audio/playback.py +++ b/ovos_audio/playback.py @@ -112,6 +112,8 @@ def clear_queue(self): def begin_audio(self, message=None): """Perform beginning of speech actions.""" if self.bus: + if not self.tts.config.get("pulse_duck", False): + self.bus.emit(Message("ovos.common_play.duck")) message = message or Message("speak") self.bus.emit(message.forward("recognizer_loop:audio_output_start")) else: @@ -125,6 +127,8 @@ def end_audio(self, listen, message=None): listen (bool): True if listening event should be emitted """ if self.bus: + if not self.tts.config.get("pulse_duck", False): + self.bus.emit(Message("ovos.common_play.unduck")) # Send end of speech signals to the system message = message or Message("speak") self.bus.emit(message.forward("recognizer_loop:audio_output_end")) diff --git a/ovos_audio/service.py b/ovos_audio/service.py index 83689a9..8d2a255 100644 --- a/ovos_audio/service.py +++ b/ovos_audio/service.py @@ -467,15 +467,19 @@ def handle_instant_play(self, message): if self.validate_source and not validate_message_context(message): LOG.debug("ignoring playback, message is not from a native source") return + audio_file = message.data.get("uri") hex_audio = message.data.get("binary_data") audio_ext = message.data.get("audio_ext") - ensure_volume = message.data.get("force_unmute", False) if hex_audio: audio_file = self._path_from_hexdata(hex_audio, audio_ext) if not audio_file: raise ValueError(f"message.data needs to provide 'uri' or 'binary_data': {message.data}") audio_file = self._resolve_sound_uri(audio_file) + + # volume handling and audio service ducking + ensure_volume = message.data.get("force_unmute", False) + duck_pulse_handled = bool(self.tts and self.tts.config.get("pulse_duck")) if ensure_volume: volume_poll: Message = self.bus.wait_for_response(Message("mycroft.volume.get")) volume = volume_poll.data.get("percent", 0) if volume_poll else 80 @@ -487,16 +491,21 @@ def handle_instant_play(self, message): volume_changed = True elif muted: self.bus.emit(Message("mycroft.volume.unmute")) - + if self.audio.current and not duck_pulse_handled: + self.audio.current.lower_volume() + play_audio(audio_file).wait() + # return to previous state + if self.audio.current and not duck_pulse_handled: + self.audio.current.restore_volume() if ensure_volume: if volume_changed: self.bus.emit(Message("mycroft.volume.set", {"percent": volume, "play_sound": False})) if muted: self.bus.emit(Message("mycroft.volume.mute")) - + self.bus.emit(message.response({})) def handle_get_languages_tts(self, message):