From c27916d0d320a33ac19d74a1b33badb7e281d464 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 1 May 2024 21:33:13 +0100 Subject: [PATCH] hotfix/voice_kwarg (#223) * hotfix/voice_kwarg was not being passed to kwargs in TTS template * get rid of deprecation warnings * test --- ovos_plugin_manager/templates/tts.py | 8 +++++--- test/unittests/test_tts.py | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ovos_plugin_manager/templates/tts.py b/ovos_plugin_manager/templates/tts.py index f24b2fff..d911f784 100644 --- a/ovos_plugin_manager/templates/tts.py +++ b/ovos_plugin_manager/templates/tts.py @@ -547,6 +547,10 @@ def _get_ctxt(self, kwargs=None) -> TTSContext: sess = SessionManager.get(message) kwargs["lang"] = sess.lang + # voice from config + if "voice" not in kwargs: + kwargs["voice"] = self.voice + # filter kwargs accepted by this specific plugin kwargs = {k: v for k, v in kwargs.items() if k in inspect.signature(self.get_tts).parameters @@ -555,7 +559,7 @@ def _get_ctxt(self, kwargs=None) -> TTSContext: LOG.debug(f"TTS kwargs: {kwargs}") return TTSContext(plugin_id=self.plugin_id, lang=kwargs.get("lang") or Configuration().get("lang", "en-us"), - voice=kwargs.get("voice") or self.voice, + voice=kwargs.get("voice", "default"), synth_kwargs=kwargs) def _execute(self, sentence, ident, listen, preprocess=True, **kwargs): @@ -885,8 +889,6 @@ def get_from_cache(self, sentence): return self._get_ctxt().get_from_cache(sentence, self.audio_ext, self.config) @property - @deprecated("language is defined per request in get_tts, self.lang is not used", - "0.1.0") def lang(self): message = dig_for_message() if message: diff --git a/test/unittests/test_tts.py b/test/unittests/test_tts.py index 88b7a29f..ec3baf16 100644 --- a/test/unittests/test_tts.py +++ b/test/unittests/test_tts.py @@ -362,14 +362,14 @@ def test_tts_session(self): self.assertEqual(ctxt.plugin_id, tts.plugin_id) self.assertEqual(ctxt.lang, sess.lang) self.assertEqual(ctxt.tts_id, f"{tts.plugin_id}/default/en-us") - self.assertEqual(ctxt.synth_kwargs, {'lang': 'en-us'}) + self.assertEqual(ctxt.synth_kwargs, {'lang': 'en-us', "voice": "default"}) sess = Session(session_id="123", lang="klingon") m = Message("speak", context={"session": sess.serialize()}) - kwargs = {"message": m} + kwargs = {"message": m, "voice": "Daghor"} ctxt = tts._get_ctxt(kwargs) self.assertEqual(ctxt.lang, sess.lang) - self.assertEqual(ctxt.tts_id, f"{tts.plugin_id}/default/klingon") - self.assertEqual(ctxt.synth_kwargs, {'lang': 'klingon'}) + self.assertEqual(ctxt.tts_id, f"{tts.plugin_id}/Daghor/klingon") + self.assertEqual(ctxt.synth_kwargs, {'lang': 'klingon', 'voice': 'Daghor'})