Pick the highest-RMS window of the clip for the bounded Demucs trim
instead of a fixed leading slice. Real uploads often open with a quiet
lead-in (silence/breath/greeting); the old first-10s trim handed the
speaker conditioner a near-silent window (~36% silence measured), which
weakened the clone and let it drift. API/signature unchanged.
Co-authored-by: Cursor <cursoragent@cursor.com>
perf(stopgap): trim reference to 10s before Demucs cleaning to bound CPU time
isolate_voice was CPU-bound at ~180s on the 2-vCPU Space, tripping the bot's voice timeouts. Decorate it with @spaces.GPU and select the CUDA onnxruntime execution provider inside the GPU scope (onnxruntime-gpu added), with a CPU fallback so local/CPU and any CUDA-init failure still work. The clone path calls the undecorated core to avoid nested GPU allocation. _MODEL_LOCK leak-fix and the /clone + /isolate_voice API signatures are unchanged.
fix: serialize prepare_conditionals->generate to stop cross-user voice leak
The TTS model stores speaker conditioning on the shared singleton
(model.conds via prepare_conditionals, read by every generate). Long
scripts are chunked and synthesized in a loop reusing those conditionals.
Concurrent /clone requests could interleave so caller B's reference
overwrote model.conds mid-loop, making caller A's later chunks speak in
B's voice. Hold a process lock for the whole set-reference->generate-all
critical section so each request owns the model exclusively. Also make the
isolate_voice temp filename uuid-based (seeded RNG could collide). API
signature (api_name=clone, inputs/outputs) unchanged.