Skip to content

Commit

Permalink
hotfix/voice_kwarg (#223)
Browse files Browse the repository at this point in the history
* hotfix/voice_kwarg

was not being passed to kwargs in TTS template

* get rid of deprecation warnings

* test
  • Loading branch information
JarbasAl authored May 1, 2024
1 parent 74636b6 commit c27916d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions ovos_plugin_manager/templates/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions test/unittests/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})

0 comments on commit c27916d

Please sign in to comment.