Skip to content

perf(profiles): reuse combined reference audio for multi-sample voices - #1211

Open
MrmoLabs wants to merge 1 commit into
jamiepine:mainfrom
MrmoLabs:perf/multisample-reference-cache
Open

MrmoLabs wants to merge 1 commit into
jamiepine:mainfrom
MrmoLabs:perf/multisample-reference-cache

Conversation

@MrmoLabs

Copy link
Copy Markdown

Multi-sample voice profiles currently decode, normalize, concatenate and rewrite their combined reference WAV on every generation, even when the samples are unchanged. This PR reuses that prepared WAV and keeps blocking reference-audio work off the API event loop.

  • Identify combined audio by the engine and ordered content/transcript hashes, so sample replacements, transcript edits and ordering changes invalidate the cache.
  • Preserve use_cache=False, cache-file recovery, profile-cache cleanup and the existing single-sample path.
  • Publish WAVs through a temporary file and atomic replacement; failed writes cannot publish a partial cache entry or destroy a previously complete entry.
  • Move shared reference decoding/normalization, source hashing and WAV writes to worker threads. No API, database schema or dependency changes.

Cache hits still read/hash source bytes to detect in-place replacements; they avoid decoding, normalization, concatenation and WAV rewriting.

Validation

Windows, Python 3.12.10, CPU PyTorch 2.11.0:

python -m pytest backend/tests/test_combined_voice_cache.py backend/tests/test_designed_profiles.py backend/tests/test_profile_delete_cascade.py backend/tests/test_profile_duplicate_names.py backend/tests/test_voice_prompt_cache_unload.py -q -p no:cacheprovider -p pytest_asyncio.plugin --asyncio-mode=auto
42 passed

The 14 new cases cover reuse, audio/transcript/engine/order invalidation, bypass, missing files, single-sample compatibility, profile-cache cleanup, worker-thread execution and failed-write recovery. The repeated-write and event-loop-thread issues were reproduced on the unmodified upstream baseline before applying the patch.

Ruff passes for the new test file; the two modified existing Python files introduce no additional diagnostics compared with upstream. git diff --check passes. CHANGELOG updated.

These are model-free regressions using a stub TTS backend; no real-model speedup, GPU, packaged-app, macOS or Linux validation is claimed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant