Skip to content

Commit

Permalink
feat/disable_cache
Browse files Browse the repository at this point in the history
make TTS caching configurable, this can be disabled in config for each TTS
  • Loading branch information
JarbasAl committed Dec 8, 2023
1 parent 5f079a1 commit 016e6db
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ovos_plugin_manager/templates/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def __init__(self, lang="en-us", config=None, validator=None,
self.ssml_tags = ssml_tags or []
self.log_timestamps = self.config.get("log_timestamps", False)

self.enable_cache = self.config.get("enable_cache", True)

self.voice = self.config.get("voice") or "default"
# TODO can self.filename be deprecated ? is it used anywhere at all?
cache_dir = get_cache_directory(self.tts_name)
Expand Down Expand Up @@ -550,7 +552,7 @@ def synth(self, sentence, **kwargs):
cache = self.get_cache(voice, lang) # cache per tts_id (lang/voice combo)

# load from cache
if sentence_hash in cache:
if self.enable_cache and sentence_hash in cache:
audio, phonemes = self.get_from_cache(sentence, **kwargs)
self.add_metric({"metric_type": "tts.synth.finished", "cache": True})
return audio, phonemes
Expand All @@ -571,8 +573,9 @@ def synth(self, sentence, **kwargs):
self.add_metric({"metric_type": "tts.synth.finished"})

# cache sentence + phonemes
self._cache_sentence(sentence, audio, phonemes, sentence_hash,
voice=voice, lang=lang)
if self.enable_cache:
self._cache_sentence(sentence, audio, phonemes, sentence_hash,
voice=voice, lang=lang)
return audio, phonemes

def _cache_phonemes(self, sentence, phonemes=None, sentence_hash=None):
Expand Down

0 comments on commit 016e6db

Please sign in to comment.