Skip to content

Commit

Permalink
use a thread to not block FakeBus (eg, voice sat) (#14)
Browse files Browse the repository at this point in the history
* 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

* Update __init__.py
  • Loading branch information
JarbasAl authored May 1, 2024
1 parent 8d27cf4 commit efa3e2e
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions ovos_PHAL_plugin_mk1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -461,19 +462,25 @@ 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():
nonlocal start, 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

# 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)
Expand Down

0 comments on commit efa3e2e

Please sign in to comment.