Perfect short clips into ideal XTTS references (refine.py)#1
Open
sinhaankur wants to merge 1 commit into
Open
Conversation
The insight: XTTS-v2 is zero-shot — it clones from ~6s of *clean* speech. So when you only have a little audio of a loved one, the win is making those seconds immaculate, not gathering more. - refine.py: score every segment (SNR/voiced/clipping/length), pick the single cleanest contiguous window, render 24kHz mono gently-normalized (XTTS's sweet spot), and emit a quality report + warnings. Returns JSON. - analyze.py: separate speakers by voice TIMBRE (log-mel band energies + pitch, k-means) instead of 3 fixed pitch bands — so a mother and a daughter at the same pitch no longer merge. Pure-Python FFT with a numpy fast path; pitch-band fallback kept. - test_refine.py: 7 offline synthetic tests (scoring, window selection, same-pitch timbre separation, single-speaker, FFT correctness). - README: document refine.py and the 'clean beats long' guidance. Verified end-to-end: an 11s three-speaker mix → a 24kHz mono reference of just the dominant speaker, with an honest quality report.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The idea
XTTS-v2 is zero-shot — it clones from ~6 seconds of clean speech. So when you only have a little audio of a loved one, the win isn't gathering more audio; it's making those few seconds immaculate and handing XTTS exactly the reference it wants.
What's new
refine.py— turns a short, imperfect clip into the best possible clone reference:loudnorm(which dulls timbre).only 5.6s…,multiple speakers…).analyze.py— speaker separation now uses voice timbre (log-mel band energies + pitch, k-means), not 3 fixed pitch bands. A mother and a daughter at the same pitch no longer get merged (the classic failure that poisons a clone). Pure-Python FFT with a numpy fast path; pitch-band fallback retained.test_refine.py— 7 offline synthetic tests: scoring ranks clean > noisy, clipping penalized, best-window selection, no cross-speaker blending, same-pitch timbre separation, single-speaker stability, FFT correctness.Verified end-to-end
An 11s three-speaker mix → a 24 kHz mono reference of just the dominant speaker, SNR 12.8 dB, with an honest report. All 7 tests pass.
{ "ok": true, "duration": 5.6, "snr_db": 12.8, "speaker": "A", "report": ["reference: 5.6s @ 24 kHz mono", "est. SNR: 12.8 dB (good)", "speakers detected: 3 — used 'A'"], "warnings": ["only 5.6s — add another clip for a truer voice", "multiple speakers — verify the chosen voice"] }Companion change in
cognitive-twin-agent:scripts/clone-voice-from-video.shnow usesrefine.pyand surfaces the quality report.