Voice prompt md5 two tier cache
Skill kjuhwa/skills-hub/skills/architecture/voice-prompt-md5-two-tier-cache
Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.
npx -y skills add kjuhwa/skills-hub --skill voice-prompt-md5-two-tier-cacheAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Cache expensive voice-cloning prompts by content-hashing the reference audio plus text, with RAM + disk tiers.
SKILL.md
2.7 KB, 518 tokens by cl100k_base, as published. Nobody here has run it
Voice prompt MD5 two-tier cache
When to use
Voice-cloning TTS builds a "voice prompt" (tokenized reference audio + embedding tensors) from a user's reference clip. The prompt is deterministic per (audio_bytes, reference_text) and takes hundreds of ms to rebuild. You want repeat generations to skip that cost entirely.
Steps
- Compute the key as
md5(audio_bytes || reference_text.encode("utf-8")). MD5 is fine here — you're not defending against a collision attacker, you're deduping content. - First tier: a process-local
dict[str, VoicePrompt]keyed by the hex digest. O(1) on a hit and skips disk I/O entirely. - Second tier:
<data_dir>/cache/<key>.promptserialized viatorch.save.torch.savehandles both raw tensors and dict-of-tensors, so the same file format survives a schema change from tensor-only to dict-of-tensors. - On load, use
torch.load(path, weights_only=True). It's safer against malicious pickles if you ever need to import a cache file from elsewhere. - On a corrupted cache file (any exception during load), unlink it and fall through to recomputation. Never raise — the cache must be best-effort.
- Write-through: on cache miss, compute, populate both tiers. Expose a cache-clear that wipes both tiers and any derived artefacts (e.g. combined audio WAVs) under the same directory.
- Provide
clear_profile_cache(profile_id)that removes onlycombined_<profile_id>_*.wavetc. — useful when a profile is edited without wiping the entire cache.
Counter / Caveats
- Include the reference text in the hash. Two clones with the same audio but different reference transcripts produce different prompts and must not collide.
- Do not pickle the tensors with
pickledirectly —torch.savehandles the device and dtype metadata across versions. - Bound the RAM tier if you ever accept many distinct profiles per session;
dictgrows without limit. AnOrderedDict+move_to_endLRU is a cheap upgrade. - If users move the app's
data_dirbetween platforms, treat the cache as ephemeral —.promptfiles are torch-version sensitive and may not load on a newer torch build. Add aCACHE_VERSIONprefix to the filename if you want eager invalidation.
Source references: backend/utils/cache.py.