From c782ad0a0d953ec3e34f06e05a0505b5e4969481 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 23 Oct 2024 22:55:32 +0100 Subject: [PATCH 1/3] feat:g2p (#109) * feat:g2p move the G2P plugin from TTS base class into ovos-audio it was only there originally as a way to deploy it to classic mycroft-core when they didn't review PRs * feat:g2p move the G2P plugin from TTS base class into ovos-audio it was only there originally as a way to deploy it to classic mycroft-core when they didn't review PRs * feat:g2p move the G2P plugin from TTS base class into ovos-audio it was only there originally as a way to deploy it to classic mycroft-core when they didn't review PRs * Update ovos_audio/playback.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- ovos_audio/playback.py | 51 +++++++++++++++++++++--------------------- ovos_audio/service.py | 6 ++--- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ovos_audio/playback.py b/ovos_audio/playback.py index 2578a17..ab0e07c 100644 --- a/ovos_audio/playback.py +++ b/ovos_audio/playback.py @@ -1,12 +1,17 @@ import random +from queue import Empty +from threading import Thread, Event +from typing import Optional + from ovos_audio.transformers import TTSTransformersService from ovos_bus_client.message import Message +from ovos_bus_client.util import get_message_lang from ovos_config import Configuration +from ovos_plugin_manager.g2p import OVOSG2PFactory +from ovos_plugin_manager.templates.g2p import OutOfVocabulary, Grapheme2PhonemePlugin from ovos_plugin_manager.templates.tts import TTS from ovos_utils.log import LOG, log_deprecation from ovos_utils.sound import play_audio -from queue import Empty -from threading import Thread, Event from time import time @@ -27,6 +32,13 @@ def __init__(self, queue=TTS.queue, bus=None): self._now_playing = None self._started = Event() self.tts_transform = TTSTransformersService(self.bus) + self.g2p = None + if Configuration().get("g2p", {}).get("module"): + LOG.debug("Loading Grapheme2Phoneme plugin for mouth movements") + try: + self.g2p: Optional[Grapheme2PhonemePlugin] = OVOSG2PFactory.create() + except: # not mission critical + pass @property def is_running(self): @@ -117,6 +129,16 @@ def _play(self): data, message.context = self.tts_transform.transform(data, message.context) self.p = play_audio(data) + + if not visemes and self.g2p is not None: + try: + visemes = self.g2p.utterance2visemes(message.data["utterance"], + get_message_lang(message)) + except OutOfVocabulary: + pass + except: + # this one is unplanned, let devs know all the info so they can fix it + LOG.exception(f"Unexpected failure in G2P plugin: {self.g2p}") if visemes: self.show_visemes(visemes) if self.p: @@ -155,30 +177,7 @@ def run(self, cb=None): while not self._terminated: self._do_playback.wait() try: - # HACK: we do these check to account for direct usages of TTS.queue singletons - speech_data = self.queue.get(timeout=2) - if len(speech_data) == 5 and isinstance(speech_data[-1], Message): - data, visemes, listen, tts_id, message = speech_data - else: - log_deprecation( - "Direct modification of TTS.queue is not recommended!\n" - "expected=(data, visemes, listen, tts_id, message)", - "0.1.0") - if len(speech_data) == 6: - # old ovos backwards compat - _, data, visemes, ident, listen, tts_id = speech_data - elif len(speech_data) == 5: - # mycroft style - tts_id = None - _, data, visemes, ident, listen = speech_data - else: - # old mycroft style TODO can this be deprecated? its very very old - listen = False - tts_id = None - _, data, visemes, ident = speech_data - - message = Message("speak", context={"session": {"session_id": ident}}) - + data, visemes, listen, tts_id, message = self.queue.get(timeout=2) self._now_playing = (data, visemes, listen, tts_id, message) self._play() except Empty: diff --git a/ovos_audio/service.py b/ovos_audio/service.py index f947e4e..c94878b 100644 --- a/ovos_audio/service.py +++ b/ovos_audio/service.py @@ -577,9 +577,9 @@ def shutdown(self): Stop any playing audio and make sure threads are joined correctly. """ self.status.set_stopping() - if self.tts.playback: - self.tts.playback.shutdown() - self.tts.playback.join() + if self.playback_thread: + self.playback_thread.shutdown() + self.playback_thread.join() if self.audio: self.audio.shutdown() From 25c6aad799b841f669712950a9e91047466ff217 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Wed, 23 Oct 2024 21:55:47 +0000 Subject: [PATCH 2/3] Increment Version to 0.3.0a1 --- ovos_audio/version.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ovos_audio/version.py b/ovos_audio/version.py index 0fde2d2..c75405b 100644 --- a/ovos_audio/version.py +++ b/ovos_audio/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 0 -VERSION_MINOR = 2 -VERSION_BUILD = 5 -VERSION_ALPHA = 0 +VERSION_MINOR = 3 +VERSION_BUILD = 0 +VERSION_ALPHA = 1 # END_VERSION_BLOCK From 4f602b0b5c2c00309058a186673356cd480f54f3 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Wed, 23 Oct 2024 21:56:09 +0000 Subject: [PATCH 3/3] Update Changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49d8c56..511de52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Changelog -## [0.2.5a1](https://github.com/OpenVoiceOS/ovos-audio/tree/0.2.5a1) (2024-10-23) +## [0.3.0a1](https://github.com/OpenVoiceOS/ovos-audio/tree/0.3.0a1) (2024-10-23) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-audio/compare/0.2.4...0.2.5a1) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-audio/compare/0.2.5...0.3.0a1) **Merged pull requests:** -- fix:b64 improvements [\#107](https://github.com/OpenVoiceOS/ovos-audio/pull/107) ([JarbasAl](https://github.com/JarbasAl)) +- feat:g2p [\#109](https://github.com/OpenVoiceOS/ovos-audio/pull/109) ([JarbasAl](https://github.com/JarbasAl))