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