From 737868055d7d2ee0596ef73e3a0dff3d68f2eff2 Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 15 Nov 2024 14:15:06 +0000 Subject: [PATCH] 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 --- ovos_workshop/skills/ovos.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 9d39f64d..67106738 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1696,7 +1696,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, + prerender_transform: Optional[Callable] = None): """ Speak a random sentence from a dialog file. @@ -1713,11 +1714,15 @@ def speak_dialog(self, key: str, data: Optional[dict] = None, """ if self.dialog_renderer: data = data or {} + utterance = self.dialog_renderer.render(key, data) + if prerender_transform is not None: + utterance = prerender_transform(utterance) 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?' )