Cache¶
Audio caching for synthesized prompts.
_cache
¶
Audio caching for synthesized prompts.
Saves synthesized audio to disk keyed by a hash of the prompt text, so repeated test runs skip the TTS call entirely.
AudioCache
¶
File-system cache for synthesized audio.
Each entry is a pair of files
Usage
cache = AudioCache() # .russo_cache/ cache = AudioCache(Path("my_cache")) # custom dir cache.get("abc123") # Audio | None cache.put("abc123", audio) cache.clear()
Source code in src/russo/_cache.py
cache_key
¶
Deterministic key from prompt text + optional extra metadata.
Extra kwargs (e.g. voice, model) are included so a change in synthesizer config invalidates the cache automatically.
Source code in src/russo/_cache.py
get
¶
get(key: str) -> Audio | None
Load cached audio, or None if not cached.
Source code in src/russo/_cache.py
put
¶
put(key: str, audio: Audio, *, prompt: str = '') -> None
Write audio + metadata to cache.
Source code in src/russo/_cache.py
clear
¶
Remove all cached entries.
Source code in src/russo/_cache.py
CachedSynthesizer
¶
CachedSynthesizer(synthesizer: Synthesizer, *, cache: AudioCache | None = None, enabled: bool = True, cache_key_extra: dict[str, Any] | None = None)
Wraps any Synthesizer with local audio caching.
Satisfies the Synthesizer protocol — drop-in replacement.
Usage
synth = CachedSynthesizer(GoogleSynthesizer(...))
Disable caching at runtime¶
synth = CachedSynthesizer(GoogleSynthesizer(...), enabled=False)
Custom cache directory¶
synth = CachedSynthesizer( GoogleSynthesizer(...), cache=AudioCache(Path("/tmp/my_cache")), )
Include synthesizer config in cache key (invalidates on config change)¶
synth = CachedSynthesizer( GoogleSynthesizer(voice="Kore", model="gemini-2.5-flash-preview-tts"), cache_key_extra={"voice": "Kore", "model": "gemini-2.5-flash-preview-tts"}, )
Clear cache¶
synth.cache.clear()
Source code in src/russo/_cache.py
synthesize
async
¶
synthesize(text: str) -> Audio
Synthesize with cache lookup/store.