TAI BUI
Back to curriculum
BuildPython

Voice Cloning & Voice Conversion

Voice cloning speaks your text in someone else's voice. Voice conversion swaps your voice for someone else's without changing what you said. Both rest on the same trick: split speaker identity from content, then recombine them from two different sources.

TIME: ~75 minutesPREREQUISITES: Phase 6 · 06 (Speaker Recognition), Phase 6 · 07 (TTS)

Learning Objectives

  • Distinguish voice cloning from voice conversion, and explain how both factor a waveform into content, speaker identity, and prosody before recombining them from two different sources.
  • Compare zero-shot, few-shot, recognition-synthesis, disentanglement, and neural-codec approaches to cloning and conversion, and name a representative model for each.
  • Build a zero-shot cloning pipeline with F5-TTS and a nearest-neighbor voice-conversion pipeline with KNN-VC, using a target speaker's reference audio.
  • Design a consent gate and audio watermark that satisfy the EU AI Act and California AB 2905 before a cloned voice ships.

The Problem

In 2026, a 5-second clip is all it takes to clone anyone's voice on a consumer GPU. Two closely related tasks fall under that umbrella:

  • Voice cloning (TTS-side): text plus a 5-second reference voice produces audio in that voice.
  • Voice conversion (speech-side): source audio of person A saying X, plus a reference voice from person B, produces audio of B saying X.

Both factor a waveform into content, speaker, and prosody, then recombine content from one source with the speaker identity of another.

ElevenLabs, F5-TTS, OpenVoice v2, and VoiceBox all ship zero-shot or few-shot cloning out of the box, and that capability cuts both ways. It powers accessibility TTS, dubbing, and assistive voices. It also powers scam calls, political deepfakes, and IP theft.

You now ship under a hard constraint: watermarking and consent gates are legally required in the EU (AI Act, enforceable August 2026) and in California (AB 2905, effective 2025). Your pipeline has to emit an inaudible watermark and refuse non-consensual clones, or it doesn't ship.

Warm-up0/3
1. A speaker verification system maps a voice clip to a fixed-length vector. What is that vector meant to capture?Warm-up
Two voice clips of different lengths go into a speaker verification system, which outputs two vectors of the same length.
Schematic. The clip lengths are illustrative.
2. In a text-to-speech system, what does the final vocoder stage do?Warm-up
A five-step text-to-speech chain: input text, two unnamed stages, a stage called vocoder, and audio out.
Schematic of the order only.
3. Two embedding vectors point in almost the same direction. What is their cosine similarity close to?Warm-up
Two arrows start at the same point and point in almost the same direction, labelled a and b. Beside them, cosine similarity equals a question mark.
Schematic. The small angle is drawn for illustration, not measured.
Check: The Problem0/2
1. How does the lesson distinguish voice cloning from voice conversion?Explain
Two rows, voice cloning and voice conversion. Each is an unknown input plus a voice sample of B, producing audio in B's voice.
Schematic.
2. Why does the lesson say a cloning pipeline cannot ship in the EU without extra components?Explain
A cloning pipeline from text and reference voice through a cloning model and two unnamed steps to the clip out, above a note: EU AI Act enforceable August 2026.
Date as given in the lesson.

The Concept

Voice cloning vs conversion: factorize, swap speaker, recombine

Zero-shot cloning. Pass a 5-second clip to a model trained on thousands of speakers. The speaker encoder maps the clip to a speaker embedding, and the TTS decoder conditions on that embedding plus the text.

Used by: F5-TTS (2024), YourTTS (2022), XTTS v2 (2024), OpenVoice v2 (2024).

Few-shot fine-tuning. Record 5-30 minutes of the target voice, then LoRA-fine-tune (update a small adapter instead of the full model) a base model for about an hour. Quality leaps from "okay" to "indistinguishable." Coqui and ElevenLabs both support this pattern, and the community runs it with F5-TTS too.

Voice conversion (VC). Two families:

  • Recognition-synthesis. Run an ASR-like model to extract a content representation (soft phoneme posteriors, PPGs), then resynthesize with the target speaker embedding. Robust to language and accent. Used by KNN-VC (2023), Diff-HierVC (2023).
  • Disentanglement. Train an autoencoder that separates content, speaker, and prosody in latent space at the bottleneck, then swap the speaker embedding at inference. Lower quality but faster. Used by AutoVC (2019), VITS-VC variants.

Neural codec-based cloning (2024+). VALL-E, VALL-E 2, NaturalSpeech 3, and VoiceBox all treat audio as discrete tokens from SoundStream or EnCodec, then train a large autoregressive or flow-matching (predict a direct path from noise to the target audio, rather than one token at a time) model over those codec tokens. Quality is comparable to ElevenLabs on short prompts.

The ethics bit, not a bolt-on

Watermarking. PerTh (Perth) and SilentCipher (2024) embed a ~16-32 bit ID imperceptibly in the audio. It survives re-encoding, streaming, and common edits, and both are production-ready open source.

Consent gates. Pair every cloned output with a verifiable consent record: "I, Rohit, on 2026-04-22, authorize this voice for X purpose." Store it in a tamper-evident log.

Detection. AASIST, RawNet2, and Wav2Vec2-AASIST ship as detectors. The ASVspoof 2025 challenge published EERs of 0.8–2.3% for state-of-the-art detectors against ElevenLabs, VALL-E 2, and Bark outputs.

Numbers (2026)

ModelZero-shot?SECS (target sim)WER (intel.)Params
F5-TTSYes0.722.1%335M
XTTS v2Yes0.653.5%470M
OpenVoice v2Yes0.702.8%220M
VALL-E 2Yes0.772.4%370M
VoiceBoxYes0.782.1%330M

SECS above 0.70 is generally indistinguishable from the target for most listeners.

Check: The Concept0/15
1. What is zero-shot voice cloning?Define
A card naming the term zero-shot voice cloning with the models the lesson lists for it: F5-TTS, YourTTS, XTTS v2 and OpenVoice v2. The definition is a question mark.
Model list as given in the lesson.
2. What is a PPG (phonetic posteriorgram)?Define
An empty-looking grid of 12 columns, one per audio frame, and 5 rows whose labels are question marks. In each column one cell is shaded.
Schematic of the grid shape. The shading and the number of rows are illustrative.
3. What is a watermark in the context of cloned audio?Define
A pipeline of text plus reference voice, cloning model, clone, a step called watermark, and shipped clip. A note names PerTh and SilentCipher as tools for that step.
Tool names as given in the lesson.
4. What does SECS measure?Define
A number line from 0.60 to 0.80 with five dots, one per model: XTTS v2 at 0.65, OpenVoice v2 at 0.70, F5-TTS at 0.72, VALL-E 2 at 0.77 and VoiceBox at 0.78.
Values from the lesson's table.
5. What is few-shot fine-tuning for voice cloning?Define
A card naming the term few-shot voice cloning with the products the lesson lists for it: Coqui, ElevenLabs and community use with F5-TTS. The definition is a question mark.
Names as given in the lesson.
6. How does the lesson describe neural codec-based cloning models like VALL-E and VoiceBox?Define
Four model names, VALL-E, VALL-E 2, NaturalSpeech 3 and VoiceBox, above a chain: audio in, unknown step, large model, unknown step, audio out.
Schematic. Names from the lesson.
7. What does AASIST do?Define
An audio clip goes into a box called AASIST, and the output is a question mark.
Schematic.
8. Why do both cloning and conversion start by factoring a waveform into content, speaker, and prosody?Explain
A waveform is split into three parts, content, speaker and prosody. An unknown step then leads to a new waveform.
Schematic.
9. What is the key difference the lesson draws between recognition-synthesis and disentanglement approaches to voice conversion?Explain
Two cards. Recognition-synthesis lists KNN-VC and Diff-HierVC, both 2023. Disentanglement lists AutoVC (2019) and VITS-VC variants.
Names as given in the lesson.
10. Why does the lesson treat watermarking as central rather than optional?Explain
A pipeline of text plus reference voice, cloning model, clone and shipped clip, with an arrow to listeners and a note that the clip reaches people outside the system.
Schematic.
11. How does a watermark differ from a detector such as AASIST?Explain
A table comparing a watermark and a detector. Examples: PerTh and SilentCipher; AASIST and RawNet2. Two rows, input and output, are question marks.
Tool names from the lesson.
12. Using the numbers table, which zero-shot model has the highest SECS, and how does the lesson read an SECS above 0.70?Apply
A five-row table of models with columns zero-shot, SECS, WER and parameters: F5-TTS, XTTS v2, OpenVoice v2, VALL-E 2 and VoiceBox.
Table copied from the lesson.
13. Among the models in the table with SECS strictly above 0.70, which has the fewest parameters?Apply
A five-row table of models with columns zero-shot, SECS, WER and parameters: F5-TTS, XTTS v2, OpenVoice v2, VALL-E 2 and VoiceBox.
Table copied from the lesson.
14. You have 20 minutes of clean recordings from one target speaker and need production-grade quality, not just a passable zero-shot result. What should you do?Apply
A block labelled 20 minutes, one speaker, clean recordings, next to the requirement of production-grade quality rather than a passable zero-shot result.
Schematic. Waveform is illustrative.
15. A dubbing studio must render an actor's performance in a client's voice. It has only about a minute of client audio, cannot train per client, and must ship in the EU. Which design fits?Design
A requirements card: render an actor's performance in the client's voice, about a minute of client audio, no training per client, ships in the EU.
Requirements restated from the stem.

Build It

Step 1: decompose with recognition-synthesis (code-only demo in main.py)

python
def clone_pipeline(ref_audio, text, target_embedder, tts_model):
    speaker_emb = target_embedder.encode(ref_audio)
    mel = tts_model(text, speaker=speaker_emb)
    return vocoder(mel)

Conceptually simple. Nearly all the real work happens inside tts_model and the speaker encoder.

Step 2: zero-shot clone with F5-TTS

python
from f5_tts.api import F5TTS
tts = F5TTS()
wav = tts.infer(
    ref_file="rohit_5s.wav",
    ref_text="The quick brown fox jumps over the lazy dog.",
    gen_text="Please add milk and bread to my list.",
)

The reference transcript has to match the audio exactly, or the alignment breaks.

Step 3: voice conversion with KNN-VC

python
import torch
from knnvc import KNNVC  # 2023 model, https://github.com/bshall/knn-vc
vc = KNNVC.load("wavlm-base-plus")
out_wav = vc.convert(source="my_voice.wav", target_pool=["alice_1.wav", "alice_2.wav"])

KNN-VC runs WavLM to extract per-frame embeddings for the source and the target pool, then replaces each source frame with its nearest neighbor in that pool. It's non-parametric and works with as little as a minute of target speech.

Step 4: embed a watermark

python
from silentcipher import SilentCipher
sc = SilentCipher(model="2024-06-01")
payload = b"consent_id:abc123;ts:1745353200"
watermarked = sc.embed(wav, sr=24000, message=payload)
detected = sc.detect(watermarked, sr=24000)   # returns payload bytes

About 32 bits of payload, and it's still detectable after an MP3 re-encode or light noise.

Step 5: consent gate

python
def cloned_inference(text, ref_audio, consent_record):
    assert verify_signature(consent_record), "Signed consent required"
    assert consent_record["speaker_id"] == hash_speaker(ref_audio)
    wav = tts.infer(ref_file=ref_audio, gen_text=text)
    wav = watermark(wav, payload=consent_record["id"])
    return wav
Check: Build It0/11
1. What is a consent gate in a cloning pipeline?Define
A quoted consent record, I, Rohit, on 2026-04-22, authorize this voice for X purpose, stored in a tamper-evident log.
Example text as given in the lesson.
2. In the lesson's KNN-VC code example, how does the conversion actually work?Define
The convert call with a source file my_voice.wav and a target pool of alice_1.wav and alice_2.wav.
Call as in the lesson's Step 3. The load line is omitted.
3. Why must the reference transcript passed to F5-TTS match the reference audio exactly?Explain
A reference audio file rohit_5s.wav next to its reference transcript, The quick brown fox jumps over the lazy dog.
File name and transcript from the lesson's Step 2. The waveform is schematic.
4. In Step 1's clone_pipeline, which line is where the target speaker's identity enters the output?Apply
The four-line clone_pipeline function from the lesson: encode the reference audio, call the TTS model with text and speaker, return the vocoder output.
Code copied from the lesson.
5. In the Step 2 F5-TTS call, which argument decides the words the generated clip speaks?Apply
The F5-TTS code from the lesson: an infer call with ref_file, ref_text and gen_text arguments.
Code copied from the lesson.
6. In Step 3, vc.convert(source="my_voice.wav", target_pool=["alice_1.wav", "alice_2.wav"]) returns audio that sounds like what?Apply
The convert call with source my_voice.wav and a target pool of alice_1.wav and alice_2.wav, producing out_wav, which is unknown.
Call copied from the lesson.
7. After Step 4, the watermarked clip is MP3-encoded and passed to sc.detect(...). What should come back?Apply
SilentCipher code: embed a payload into a clip, MP3-encode the watermarked clip, then call detect. The value returned is a question mark.
Code from the lesson's Step 4. The MP3 step is the stem's, written here as a comment.
8. What does the Step 5 consent gate check before generating a cloned voice?Apply
The cloned_inference function with its checking lines hidden, followed by the infer call, a watermark call using the consent record's id, and a return.
Code from the lesson's Step 5 with the lines before inference hidden.
9. F5-TTS output comes back with garbled, misaligned speech even though the reference clip is clean. Which input should you check first?Analyze
The three F5-TTS arguments ref_file, ref_text and gen_text, with a note that the reference clip is clean and the output is garbled and misaligned.
Arguments copied from the lesson's Step 2. The symptom is from the stem.
10. A clone leaks online and a lawyer asks who authorized it. The audio has no watermark. Which part of the Step 4 and 5 design was skipped?Analyze
A waveform labelled clip found online next to a note that no watermark payload was found and a lawyer asks who authorized the clip.
Schematic of the stem's situation.
11. A teammate wants to build the consent gate last, once clone quality is tuned. What is the flaw in that plan?Analyze
A three-step plan in order: get the clone pipeline running end to end, tune clone quality, then build the consent gate last.
The plan as stated in the question.

Use It

The 2026 stack:

SituationPick
5-sec zero-shot clone, open-sourceF5-TTS or OpenVoice v2
Commercial production cloningElevenLabs Instant Voice Clone v2.5
Voice conversion (rewriting)KNN-VC or Diff-HierVC
Many-speaker fine-tuneStyleTTS 2 + speaker adapter
Cross-lingual cloningXTTS v2 or VALL-E X
Deepfake detectionWav2Vec2-AASIST
Check: Use It0/2
1. Per the Use It table, what do you pick for a many-speaker fine-tune versus cross-lingual cloning?Apply
Two rows of the lesson's Use It table, many-speaker fine-tune and cross-lingual cloning, with the Pick column hidden.
Situations from the lesson. The Pick column is hidden here, and the other rows are left out.
2. You are building an assistive app that gives a user a Spanish-speaking clone of their English voice from a 5-second clip. Which design satisfies quality and law?Design
A 5-second clip of the user speaking English goes into an unnamed design that outputs Spanish speech in the user's own voice. The design must satisfy quality and the law.
Setup from the stem.

Pitfalls

  • Misaligned reference transcript. F5-TTS and similar require the reference text to match the reference audio exactly, punctuation included.
  • Reverberant reference. Echo kills the clone. Record dry, close-mic.
  • Emotional mismatch. A cheerful reference clip produces cheerful clones of everything, so match the reference emotion to the target use.
  • Language leakage. Clone an English speaker, then ask the model to speak French, and the accent often carries over anyway. Use a cross-lingual model instead (XTTS, VALL-E X).
  • No watermark. Legally unshippable in the EU from August 2026.
Check: Pitfalls0/2
1. You record a reference in an echoey stairwell in an upbeat mood, then clone serious dialogue. What should you expect?Analyze
Three cards: reference recorded in an echoey stairwell, upbeat mood of the reference, and serious dialogue as the text to clone. The resulting clone is a question mark.
Setup from the stem.
2. You clone an English speaker and ask the model for French, but the output keeps an English accent. What is the lesson's fix?Analyze
An English speaker's reference and French text go into a cloning model. The French speech comes out with an English accent still present.
Setup from the stem.

Ship It

Save as outputs/skill-voice-cloner.md. Design a cloning or conversion pipeline with consent gate + watermark + quality target.

Author's Note

The consent gate is the part people build last, once the pipeline already works, and that ordering is backwards. Build it first, even in a prototype, even when the only voice you're cloning is your own. Once clone_pipeline runs end to end on whatever reference clip was closest to hand, retrofitting a permission check into it is a much easier step to skip than adding one before you had anything worth shipping. The watermark is non-negotiable for the same reason: it's cheap to bolt on now and effectively impossible to add after a clone is already out in the world.

Exercises

  1. Easy. Run code/main.py. Demonstrates the speaker-embedding swap by computing the cosine between two "speakers" pre and post swap.
  2. Medium. Use OpenVoice v2 to clone your own voice. Measure SECS between reference and clone. Measure CER via Whisper.
  3. Hard. Apply SilentCipher watermark to 20 clones, run them through 128 kbps MP3 encode+decode, detect the payload. Report bit-accuracy.

Key Terms

TermWhat people sayWhat it actually means
Zero-shot clone5 seconds is enoughPretrained model + speaker embedding; no training.
PPGPhonetic posteriorgramPer-frame ASR posteriors used as language-agnostic content rep.
KNN-VCNearest-neighbor conversionReplace each source frame with nearest target-pool frame.
Neural codec TTSVALL-E styleAR model over EnCodec/SoundStream tokens.
WatermarkInaudible signatureBits embedded in audio, survive re-encode.
SECSCloning fidelityCosine between target and clone speaker embeddings.
AASISTDeepfake detectorAnti-spoof model; detects synthesized speech.

Further Reading

Code

Ships With