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/tts_reload #57

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ovos_audio/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import os.path
import time
import json
from hashlib import md5
from os.path import exists
from queue import Queue
Expand Down Expand Up @@ -326,18 +327,24 @@ def _maybe_reload_tts(self):
Load TTS modules if not yet loaded or if configuration has changed.
Optionally pre-loads fallback TTS if configured
"""
config = self.config.get("tts", {})
config = Configuration().get("tts", {})
tts_m = config.get("module", "")
ftts_m = config.get("fallback_module", "")
_tts_hash = hash(json.dumps(config.get(tts_m, {}),
sort_keys=True))
_ftts_hash = hash(json.dumps(config.get(ftts_m, {}),
sort_keys=True))

# update TTS object if configuration has changed
if not self._tts_hash or self._tts_hash != config.get("module", ""):
if not self._tts_hash or self._tts_hash != _tts_hash:
with self.lock:
if self.tts:
self.tts.shutdown()
# Create new tts instance
LOG.info("(re)loading TTS engine")
self.tts = TTSFactory.create(config)
self.tts.init(self.bus, self.playback_thread)
self._tts_hash = config.get("module", "")
self._tts_hash = _tts_hash

# if fallback TTS is the same as main TTS dont load it
if config.get("module", "") == config.get("fallback_module", "") or not config.get("fallback_module", ""):
Expand All @@ -349,14 +356,14 @@ def _maybe_reload_tts(self):
return

if not self._fallback_tts_hash or \
self._fallback_tts_hash != config.get("fallback_module", ""):
self._fallback_tts_hash != ftts_m:
with self.lock:
if self.fallback_tts:
self.fallback_tts.shutdown()
# Create new tts instance
LOG.info("(re)loading fallback TTS engine")
self._get_tts_fallback()
self._fallback_tts_hash = config.get("fallback_module", "")
self._fallback_tts_hash = _ftts_hash

def execute_tts(self, utterance, ident, listen=False, message: Message = None):
"""Mute mic and start speaking the utterance using selected tts backend.
Expand Down
1 change: 1 addition & 0 deletions test/unittests/test_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def execute(*args, **kwargs):

speech = PlaybackService(bus=bus)
speech.tts = FailingTTS()
speech._tts_hash = "123failing"

speech.execute_tts("hello", "123")
self.assertTrue(speech.fallback_tts.execute.called)
Expand Down
Loading