Skip to content

Commit

Permalink
Merge branch 'dev' into PATCH_OvosUtilsCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel authored May 7, 2024
2 parents 4f82bf6 + de1a52f commit 7a50718
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [0.0.16a28](https://github.com/OpenVoiceOS/OVOS-workshop/tree/0.0.16a28) (2024-05-07)

[Full Changelog](https://github.com/OpenVoiceOS/OVOS-workshop/compare/0.0.16a27...0.0.16a28)

**Implemented enhancements:**

- feat/wait\_while\_speaking [\#190](https://github.com/OpenVoiceOS/OVOS-workshop/pull/190) ([JarbasAl](https://github.com/JarbasAl))

## [0.0.16a27](https://github.com/OpenVoiceOS/OVOS-workshop/tree/0.0.16a27) (2024-05-04)

[Full Changelog](https://github.com/OpenVoiceOS/OVOS-workshop/compare/0.0.16a26...0.0.16a27)
Expand Down
45 changes: 26 additions & 19 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -538,7 +538,7 @@ def system_unit(self) -> str:
"""
sess = SessionManager.get()
return sess.system_unit

@property
def date_format(self) -> str:
"""
Expand All @@ -556,7 +556,7 @@ def time_format(self) -> str:
"""
sess = SessionManager.get()
return sess.time_format

@property
def location(self) -> dict:
"""
Expand Down Expand Up @@ -1666,18 +1666,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):
Expand Down Expand Up @@ -1707,7 +1698,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, "
Expand All @@ -1719,19 +1711,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
Expand All @@ -1754,6 +1756,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
Expand Down
2 changes: 1 addition & 1 deletion ovos_workshop/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
VERSION_MAJOR = 0
VERSION_MINOR = 0
VERSION_BUILD = 16
VERSION_ALPHA = 27
VERSION_ALPHA = 28
# END_VERSION_BLOCK

0 comments on commit 7a50718

Please sign in to comment.