Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Move TTS cache curation to TextToSpeechCache #2869

Merged
merged 2 commits into from
Mar 19, 2021
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
6 changes: 5 additions & 1 deletion mycroft/tts/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import requests

from mycroft.util.file_utils import (
ensure_directory_exists, get_cache_directory
ensure_directory_exists, get_cache_directory, curate_cache
)
from mycroft.util.log import LOG

Expand Down Expand Up @@ -282,6 +282,10 @@ def clear(self):
elif cache_file_path.is_file():
cache_file_path.unlink()

def curate(self):
"""Remove cache data if disk space is running low."""
curate_cache(self.temporary_cache_dir, min_free_percent=100)

def define_audio_file(self, sentence_hash: str) -> AudioFile:
"""Build an instance of an object representing an audio file."""
audio_file = AudioFile(
Expand Down
5 changes: 1 addition & 4 deletions mycroft/tts/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
#
from copy import deepcopy
import hashlib
import os
import random
import re
Expand Down Expand Up @@ -225,10 +224,8 @@ def end_audio(self, listen=False):
self.bus.emit(Message("recognizer_loop:audio_output_end"))
if listen:
self.bus.emit(Message('mycroft.mic.listen'))
# Clean the cache as needed
cache_dir = mycroft.util.get_cache_directory("tts/" + self.tts_name)
mycroft.util.curate_cache(cache_dir, min_free_percent=100)

self.cache.curate()
# This check will clear the "signal"
check_for_signal("isSpeaking")

Expand Down
11 changes: 11 additions & 0 deletions test/unittests/tts/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ def test_clear_cache(self):
tts_cache.clear()
cache_contents = [path for path in self.cache_dir.iterdir()]
self.assertListEqual([], cache_contents)

@patch('mycroft.tts.cache.curate_cache')
def test_curate_cache(self, curate_mock):
tts_cache = TextToSpeechCache(
tts_config=dict(preloaded_cache=self.cache_dir),
tts_name="Test",
audio_file_type="wav"
)
tts_cache.curate()
curate_mock.assert_called_with(tts_cache.temporary_cache_dir,
min_free_percent=100)