Skip to content

Commit

Permalink
fix/tts_reload
Browse files Browse the repository at this point in the history
TTS reload was only working for plugin changes

the check for config changes only accounted for module, not for the whole config, so changing voice etc would require a reload
  • Loading branch information
JarbasAl committed Apr 17, 2024
1 parent 63391b6 commit db19b51
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ovos_audio/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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 @@ -301,18 +302,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 @@ -324,14 +331,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

0 comments on commit db19b51

Please sign in to comment.