From 932e721a360a49b487b3659698972a7284a0ed6c Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 1 May 2024 23:38:37 +0100 Subject: [PATCH] use a thread to not block FakeBus (eg, voice sat) showing visemes in a mark1 voice sat could block TTS from executing, due to the event handlers not being True threads --- ovos_PHAL_plugin_mk1/__init__.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ovos_PHAL_plugin_mk1/__init__.py b/ovos_PHAL_plugin_mk1/__init__.py index ba99247..ffee2bf 100644 --- a/ovos_PHAL_plugin_mk1/__init__.py +++ b/ovos_PHAL_plugin_mk1/__init__.py @@ -4,6 +4,7 @@ import serial from ovos_bus_client.message import Message +from ovos_utils import create_daemon from ovos_utils.log import LOG from ovos_utils.network_utils import is_connected @@ -461,19 +462,24 @@ def on_viseme_list(self, message=None): if message and message.data: start = message.data['start'] visemes = message.data['visemes'] - self.showing_visemes = True - previous_end = -1 - for code, end in visemes: - if not self.showing_visemes: - break - if end < previous_end: - start = time.time() - previous_end = end - if time.time() < start + end: - self.writer.write('mouth.viseme=' + code) - sleep(start + end - time.time()) - self.writer.write("mouth.reset") - self.showing_visemes = False + + def animate_mouth(): + self.showing_visemes = True + previous_end = -1 + for code, end in visemes: + if not self.showing_visemes: + break + if end < previous_end: + start = time.time() + previous_end = end + if time.time() < start + end: + self.writer.write('mouth.viseme=' + code) + sleep(start + end - time.time()) + self.writer.write("mouth.reset") + self.showing_visemes = False + + # use a thread to not block FakeBus (eg, voice sat) + create_daemon(animate_mouth) def on_text(self, message=None): """Display text (scrolling as needed)