TTS: include mp3 files in cache stats

TTSService._put_cache writes .mp3 for MP3 audio (ID3/MPEG-framed bytes) and
.wav otherwise, and the rest of the class treats both as cache entries
(_get_cache iterates (".mp3", ".wav"); eviction globs "*.*"). But
get_stats() enumerated the cache with `glob("*.wav")` only, so both
cache_entries and cache_size_mb undercounted — reporting 0 whenever the
cache held MP3 files, which is the common case for most TTS providers.

Glob both extensions so the reported stats match what's actually cached.

tests/test_tts_cache_stats.py writes an MP3-headed blob via _put_cache and
asserts get_stats() reports one entry with non-zero size. Fails before this
change.
This commit is contained in:
Tatlatat
2026-06-02 18:43:29 +07:00
committed by GitHub
parent 3885f9fa90
commit 51cf63009e
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -188,7 +188,7 @@ class TTSService:
provider = settings["tts_provider"]
tts_enabled = settings.get("tts_enabled", True)
cache_files = list(self.cache_dir.glob("*.wav"))
cache_files = list(self.cache_dir.glob("*.wav")) + list(self.cache_dir.glob("*.mp3"))
cache_size = sum(f.stat().st_size for f in cache_files)
is_available = self.available and tts_enabled