Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ovos-audio compat. #177

Merged
merged 15 commits into from
Sep 16, 2024
14 changes: 10 additions & 4 deletions neon_audio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,21 @@ def main(*args, **kwargs):
check_for_signal("isSpeaking")
Lock("audio")
setup_locale()
service = NeonPlaybackService(*args, **kwargs)
service.start()
wait_for_exit_signal()
try:
service = NeonPlaybackService(*args, **kwargs)
LOG.info("Service init completed")
service.start()
wait_for_exit_signal()
except Exception as e:
LOG.exception(e)
service = None
if malloc_running:
try:
print_malloc(snapshot_malloc())
except Exception as e:
LOG.error(e)
service.shutdown()
if service:
service.shutdown()


def deprecated_entrypoint():
Expand Down
22 changes: 10 additions & 12 deletions neon_audio/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import ovos_plugin_manager.templates.tts

from threading import Event

from ovos_utils.log import LOG, log_deprecation
from neon_audio.tts import TTSFactory
from neon_utils.messagebus_utils import get_messagebus
Expand Down Expand Up @@ -84,21 +85,15 @@ def __init__(self, ready_hook=on_ready, error_hook=on_error,
from neon_audio.utils import patch_config
patch_config(audio_config)
bus = bus or get_messagebus()
# Override all the previously loaded signal methods
from neon_utils.signal_utils import init_signal_handlers, \
init_signal_bus
init_signal_bus(bus)
init_signal_handlers()
from neon_utils.signal_utils import create_signal, check_for_signal
ovos_audio.service.check_for_signal = check_for_signal
ovos_plugin_manager.templates.tts.check_for_signal = check_for_signal
ovos_plugin_manager.templates.tts.create_signal = create_signal
from neon_utils.signal_utils import create_signal

from neon_audio.tts.neon import NeonPlaybackThread
ovos_audio.service.PlaybackThread = NeonPlaybackThread
PlaybackService.__init__(self, ready_hook, error_hook, stopping_hook,
alive_hook, started_hook, watchdog, bus,
disable_ocp)
disable_ocp, validate_source=False)
del self.playback_thread
from neon_audio.tts.neon import NeonPlaybackThread
from ovos_plugin_manager.tts import TTS
self.playback_thread = NeonPlaybackThread(TTS.queue, self.bus)
LOG.debug(f'Initialized tts={self._tts_hash} | '
f'fallback={self._fallback_tts_hash}')
create_signal("neon_speak_api") # Create signal so skills use API
Expand Down Expand Up @@ -186,3 +181,6 @@ def handle_get_tts(self, message):
def init_messagebus(self):
self.bus.on('neon.get_tts', self.handle_get_tts)
PlaybackService.init_messagebus(self)
self.bus.remove("speak", PlaybackService.handle_speak)
self.bus.on("speak", self.handle_speak)
LOG.info("Initialized messagebus")
4 changes: 2 additions & 2 deletions neon_audio/tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def create(config=None):
"en-us")

tts_config = get_tts_config(config)
tts_lang = tts_config["lang"]
clazz = OVOSTTSFactory.get_class(tts_config)
if not clazz:
LOG.error(f"Could not find plugin: {tts_config.get('module')}")
return
tts = WrappedTTS(clazz, tts_lang, tts_config)
tts = WrappedTTS(clazz, config=tts_config)
tts.validator.validate()
LOG.info(f"Initialized tts: {tts.tts_name}")
return tts
15 changes: 13 additions & 2 deletions neon_audio/tts/neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def end_audio(self, listen, message=None):
check_for_signal("isSpeaking")

def _play(self):
LOG.debug(f"Start playing {self._now_playing}")
# wav_file, vis, listen, ident, message
ident = self._now_playing[3]
message = self._now_playing[4]
Expand All @@ -180,7 +181,7 @@ def _play(self):
ident = message.context.get('ident') or \
message.context.get('session', {}).get('session_id')

super()._play()
PlaybackThread._play(self)
# Notify playback is finished
LOG.info(f"Played {ident}")
self.bus.emit(message.forward(ident))
Expand All @@ -192,9 +193,18 @@ def _play(self):
**_sort_timing_metrics(
message.context['timing'])}))

def pause(self):
LOG.debug(f"Playback thread paused")
PlaybackThread.pause(self)

def resume(self):
LOG.debug(f"Playback thread resumed")
PlaybackThread.resume(self)


class WrappedTTS(TTS):
def __new__(cls, base_engine, *args, **kwargs):
LOG.info(f"Creating wrapped TTS object for {base_engine}")
base_engine.execute = cls.execute
base_engine.get_multiple_tts = cls.get_multiple_tts
# TODO: Below method is only to bridge compatibility
Expand Down Expand Up @@ -306,7 +316,6 @@ def get_multiple_tts(self, message, **kwargs) -> dict:
for request in tts_requested:
tts_lang = kwargs["lang"] = request["language"]
# Check if requested tts lang matches internal (text) lang
# TODO: `self.lang` should come from the incoming message
if tts_lang.split("-")[0] != skill_lang.split("-")[0]:
self.cached_translations.setdefault(tts_lang, {})

Expand Down Expand Up @@ -359,6 +368,7 @@ def execute(self, sentence: str, ident: str = None, listen: bool = False,
kwargs: (dict) optional keyword arguments to be passed to
TTS engine get_tts method
"""
LOG.debug(f"execute: {sentence}")
stopwatch = Stopwatch("get_tts", True, self.bus)
if message:
# Make sure to set the speaking signal now
Expand Down Expand Up @@ -400,6 +410,7 @@ def execute(self, sentence: str, ident: str = None, listen: bool = False,
vis = self.viseme(r["phonemes"]) if r["phonemes"] \
else None
# queue for playback
LOG.debug(f"Queue playback of: {wav_file}")
self.queue.put((wav_file, vis, listen, ident, message))
self.handle_metric({"metric_type": "tts.queued"})
else:
Expand Down
2 changes: 2 additions & 0 deletions neon_audio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def build_extra_dependency_list(config: Union[dict, Configuration], additional:

return dependencies


@deprecated("Replaced by `neon_utils.packaging_utils.install_packages_from_pip`", "2.0.0")
def install_tts_plugin(plugin: str) -> bool:
"""
Expand All @@ -85,6 +86,7 @@ def install_tts_plugin(plugin: str) -> bool:
_, tmp_file = mkstemp()
with open(tmp_file, 'w') as f:
constraints = '\n'.join(get_package_dependencies("neon-audio"))
constraints += '\n' + '\n'.join(get_package_dependencies("ovos-audio"))
f.write(constraints)
LOG.info(f"Constraints={constraints}")
LOG.info(f"Requested installation of plugin: {plugin}")
Expand Down
8 changes: 4 additions & 4 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ovos-audio~=0.2
ovos-audio~=0.0,>=0.0.2
ovos-utils~=0.0,>=0.0.35
ovos-config~=0.0,>=0.0.10
phoneme-guesser~=0.1
ovos-plugin-manager~=0.0,>=0.0.26
ovos-plugin-manager~=0.0,>=0.0.26a16
neon-utils[network]~=1.9
click~=8.0
click-default-group~=1.2
ovos-bus-client~=0.0.3
ovos-bus-client~=0.0,>=0.0.3

# Default OCP backend + plugins
ovos-plugin-common-play~=0.1
ovos-plugin-common-play~=0.0,>=0.0.6
ovos-ocp-m3u-plugin~=0.0.1
ovos-ocp-rss-plugin~=0.0.2
ovos-ocp-files-plugin~=0.13
Expand Down
Loading