agentsclimarketplace

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.

Install
npx -y skills add kjuhwa/skills-hub --skill voice-prompt-md5-two-tier-cache

Assembled 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

  1. 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.
  2. First tier: a process-local dict[str, VoicePrompt] keyed by the hex digest. O(1) on a hit and skips disk I/O entirely.
  3. Second tier: <data_dir>/cache/<key>.prompt serialized via torch.save. torch.save handles both raw tensors and dict-of-tensors, so the same file format survives a schema change from tensor-only to dict-of-tensors.
  4. 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.
  5. On a corrupted cache file (any exception during load), unlink it and fall through to recomputation. Never raise — the cache must be best-effort.
  6. 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.
  7. Provide clear_profile_cache(profile_id) that removes only combined_<profile_id>_*.wav etc. — 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 pickle directly — torch.save handles the device and dtype metadata across versions.
  • Bound the RAM tier if you ever accept many distinct profiles per session; dict grows without limit. An OrderedDict + move_to_end LRU is a cheap upgrade.
  • If users move the app's data_dir between platforms, treat the cache as ephemeral — .prompt files are torch-version sensitive and may not load on a newer torch build. Add a CACHE_VERSION prefix to the filename if you want eager invalidation.

Source references: backend/utils/cache.py.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.