Skip to content

Self-hosted AI workspace.

Python

TTS: include mp3 files in cache stats

Tatlatat4106ee2f481c
diff --git a/services/tts/tts_service.py b/services/tts/tts_service.py
index a78c8a7da..79820f23c 100644
--- a/services/tts/tts_service.py
+++ b/services/tts/tts_service.py
@@ -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
diff --git a/tests/test_tts_cache_stats.py b/tests/test_tts_cache_stats.py
new file mode 100644
index 000000000..00d2fe1c9
--- /dev/null
+++ b/tests/test_tts_cache_stats.py
@@ -0,0 +1,12 @@
+from services.tts.tts_service import TTSService
+
+
+def test_tts_cache_stats_counts_mp3(tmp_path):
+ service = TTSService(cache_dir=str(tmp_path))
+
+ # Put an MP3-headed blob (starts with b'ID3') into cache, with size > 1MB so cache_size_mb > 0
+ service._put_cache("k", b"ID3" + b"x" * (1024 * 1024))
+
+ stats = service.get_stats()
+ assert stats["cache_entries"] == 1
+ assert stats["cache_size_mb"] > 0