From e84f78b3df89aeec40abaab73c8d193002b60c12 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Wed, 13 Mar 2024 18:19:29 +0000 Subject: [PATCH 1/2] rebase on https://github.com/OpenVoiceOS/ovos-bus-client/pull/93 feat/wait_while_speaking extract into helper method + add wait flag to play_audio --- ovos_workshop/skills/ovos.py | 45 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 16f8c94a..24f96ea8 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -529,7 +529,7 @@ def dialog_renderer(self) -> Optional[MustacheDialogRenderer]: session or else from Configuration. """ return self.resources.dialog_renderer - + @property def system_unit(self) -> str: """ @@ -538,7 +538,7 @@ def system_unit(self) -> str: """ sess = SessionManager.get() return sess.system_unit - + @property def date_format(self) -> str: """ @@ -556,7 +556,7 @@ def time_format(self) -> str: """ sess = SessionManager.get() return sess.time_format - + @property def location(self) -> dict: """ @@ -1633,18 +1633,9 @@ def speak(self, utterance: str, expect_response: bool = False, if wait: timeout = wait if isinstance(wait, int) else 15 - sessid = SessionManager.get(m).session_id - event = Event() - - def handle_output_end(msg): - sess = SessionManager.get(msg) - if sessid == sess.session_id: - event.set() - - self.bus.on("recognizer_loop:audio_output_end", handle_output_end) - event.wait(timeout=timeout) - self.bus.remove("recognizer_loop:audio_output_end", - handle_output_end) + sess = SessionManager.get(m) + sess.is_speaking = True + SessionManager.wait_while_speaking(timeout, sess) def speak_dialog(self, key: str, data: Optional[dict] = None, expect_response: bool = False, wait: Union[bool, int] = False): @@ -1674,7 +1665,8 @@ def speak_dialog(self, key: str, data: Optional[dict] = None, ) self.speak(key, expect_response, wait, {}) - def _play_audio_old(self, filename: str, instant: bool = False): + def _play_audio_old(self, filename: str, instant: bool = False, + wait: Union[bool, int] = False): """ compat for ovos-core <= 0.0.7 """ if instant: LOG.warning("self.play_audio instant flag requires ovos-core >= 0.0.8, " @@ -1686,19 +1678,29 @@ def _play_audio_old(self, filename: str, instant: bool = False): {"filename": filename, # TODO - deprecate filename in ovos-audio "uri": filename # new namespace })) - - def _play_audio_classic(self, filename: str, instant: bool = False): + if wait: + timeout = wait if isinstance(wait, int) else 30 + sess = SessionManager.get(message) + sess.is_speaking = True + SessionManager.wait_while_speaking(timeout, sess) + + def _play_audio_classic(self, filename: str, instant: bool = False, + wait: Union[bool, int] = False): """ compat for classic mycroft-core """ LOG.warning("self.play_audio requires ovos-core >= 0.0.4, " "falling back to local skill playback") play_audio(filename).wait() @backwards_compat(pre_008=_play_audio_old, classic_core=_play_audio_classic) - def play_audio(self, filename: str, instant: bool = False): + def play_audio(self, filename: str, instant: bool = False, + wait: Union[bool, int] = False): """ Queue and audio file for playback @param filename: File to play @param instant: if True audio will be played instantly instead of queued with TTS + @param wait: set to True to block while the audio + is being played for 15 seconds. Alternatively, set + to an integer to specify a timeout in seconds. """ message = dig_for_message() or Message("") # if running in docker we need to send binary data to the ovos-audio container @@ -1721,6 +1723,11 @@ def play_audio(self, filename: str, instant: bool = False): "binary_data": bindata} self.bus.emit(message.forward(mtype, data)) + if wait: + timeout = wait if isinstance(wait, int) else 30 + sess = SessionManager.get(message) + sess.is_speaking = True + SessionManager.wait_while_speaking(timeout, sess) def __get_response_v1(self, session=None): """Helper to get a response from the user From bf6a04467059272cf6e4d0bec35771189aa0aba2 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Fri, 3 May 2024 18:40:03 +0100 Subject: [PATCH 2/2] Update requirements.txt --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2b1b3375..e4ba1b31 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,5 @@ ovos-utils >= 0.1.0a7, < 0.2.0 -ovos-bus-client < 0.1.0, >=0.0.9a17 +ovos-bus-client < 0.1.0, >=0.0.9a19 ovos_config < 0.2.0,>=0.0.12 ovos_backend_client < 0.2.0, >=0.1.0 ovos-lingua-franca~=0.4, >=0.4.6