Skip to content

Commit

Permalink
feat:utterance_modifiers (#291)
Browse files Browse the repository at this point in the history
* feat:utterance_modifiers

allow skills to access the utterance choosen by self.speak_dialog

either to modify it (eg, pronounce numbers) or just to passively monitor it

* feat:utterance_modifiers

allow skills to access the utterance choosen by self.speak_dialog

either to modify it (eg, pronounce numbers) or just to passively monitor it
  • Loading branch information
JarbasAl authored Nov 20, 2024
1 parent 592fd43 commit 7bd9062
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,8 @@ def speak(self, utterance: str, expect_response: bool = False,
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):
expect_response: bool = False, wait: Union[bool, int] = False,
render_callback: Optional[Callable[[str, str], str]] = None):
"""
Speak a random sentence from a dialog file.
Expand All @@ -1678,14 +1679,31 @@ def speak_dialog(self, key: str, data: Optional[dict] = None,
wait (Union[bool, int]): set to True to block while the text
is being spoken for 15 seconds. Alternatively, set
to an integer to specify a timeout in seconds.
render_callback (Optional[Callable[[str, str], str]]): A callable
function that
transforms the
utterance before
it is spoken.
The function
should accept
the utterance
string and the
language as input
and return the
modified string.
Defaults to None.
"""
if self.dialog_renderer:
data = data or {}
utterance = self.dialog_renderer.render(key, data)
if render_callback is not None:
utterance = render_callback(utterance, self.lang)
self.speak(
self.dialog_renderer.render(key, data),
utterance,
expect_response, wait, meta={'dialog': key, 'data': data}
)
else:
# TODO - change this behaviour, speaking the dialog file name isn't that helpful!
self.log.error(
'dialog_render is None, does the locale/dialog folder exist?'
)
Expand Down

0 comments on commit 7bd9062

Please sign in to comment.