Mistake-maker + Improv-style programmer since 2010
KokoClone is a fast, real-time compatible multilingual voice cloning system built on top of Kokoro-ONNX, one of the fastest open-source neural TTS engines available today.
It allows you to:
Generate native speech in English (en), Hindi (hi), French (fr), Japanese (ja), Chinese (zh), Italian (it), Portuguese (pt), and Spanish (es).
Upload a 3–10 second voice sample and KokoClone instantly transfers its vocal characteristics to the generated speech.
Upload any existing speech recording and re-voice it to sound like a reference speaker. The pipeline skips TTS entirely and runs purely through the Kanade voice-conversion model. Works on recordings of any length thanks to automatic VRAM-aware chunking!
On the first run, the required model weights (.onnx and .bin files) are automatically downloaded from Hugging Face and placed in the correct directories.
Built on Kokoro's efficient ONNX runtime pipeline, KokoClone detects your hardware and runs smoothly on both standard laptops (CPU) and workstations (GPU).
Try it instantly without installing anything:
👉 KokoClone on Hugging Face Spaces
You can set up KokoClone using either Conda (Recommended) or uv.
git clone https://github.com/Ashish-Patnaik/kokoclone.git
cd kokoclone
conda create -n kokoclone python=3.12.12 -y
conda activate kokoclone
For CPU Users (Mac / Standard Laptops):
pip install torch torchaudio --index-url [https://download.pytorch.org/whl/cpu](https://download.pytorch.org/whl/cpu)
pip install -r requirements.txt
For GPU Users (Nvidia GPUs):
pip install -r requirements.txt
pip install kokoro-onnx[gpu]
uvIf you prefer uv for fast package management:
# For CPU Users
uv sync
# For GPU Users (Nvidia)
uv sync --extra gpu
# Activate the environment
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
KokoClone is highly flexible and can be used via Web UI, HTTP API, CLI, or Python API.
Launch the interactive web app:
python app.py
Generate speech directly from your terminal.
Text to cloned speech (default mode):
python cli.py --text "Hello from KokoClone" --lang en --ref reference.wav --out output.wav
Audio to re-voiced speech:
python cli.py --mode convert --source original_speech.wav --ref target_voice.wav --out revoiced.wav
| Argument | Default | Description |
|---|---|---|
--mode |
tts |
tts (text → speech) or convert (audio → re-voiced audio) |
--text |
— | Text to synthesize (required for tts mode) |
--lang |
en |
Language code: en hi fr ja zh it es pt |
--source |
— | Path to source audio (required for convert mode) |
--ref |
— | Path to reference voice audio (always required) |
--out |
output.wav |
Output file path |
Integrate KokoClone into your own Python applications.
Text to Cloned Speech:
from core.cloner import KokoClone
cloner = KokoClone()
cloner.generate(
text="This voice is cloned using KokoClone.",
lang="en",
reference_audio="reference.wav",
output_path="output.wav"
)
Audio-to-Audio Voice Conversion:
import soundfile as sf
from kanade_tokenizer import load_audio
from core.cloner import KokoClone
from core.chunked_convert import chunked_voice_conversion
cloner = KokoClone()
# Load audio tensors
source_wav = load_audio("source_speech.wav", sample_rate=cloner.sample_rate).to(cloner.device)
ref_wav = load_audio("target_voice.wav", sample_rate=cloner.sample_rate).to(cloner.device)
# Convert using VRAM-aware chunking
converted = chunked_voice_conversion(
kanade=cloner.kanade,
vocoder_model=cloner.vocoder,
source_wav=source_wav,
ref_wav=ref_wav,
sample_rate=cloner.sample_rate,
)
sf.write("revoiced_output.wav", converted.numpy(), cloner.sample_rate)
OpenAI-shaped speech endpoint plus a multipart clone endpoint:
uvicorn api:app --host 0.0.0.0 --port 8880
| Endpoint | Purpose |
|---|---|
POST /v1/audio/speech |
Stock Kokoro TTS — JSON { "model", "input", "voice" } |
POST /v1/audio/clone |
Zero-shot clone — multipart text + ref_audio |
GET /health |
Health / device |
GET /v1/models |
Model list |
GET /v1/voices |
Default Kokoro voice ids per language |
GET /v1/languages |
Supported language ids |
/docs |
Swagger UI |
Clone example:
curl -X POST "http://localhost:8880/v1/audio/clone" \
-F "text=Hello from KokoClone" \
-F "language_id=en" \
-F "ref_audio=@reference.wav" \
--output clone.wav
Speech example:
curl -X POST "http://localhost:8880/v1/audio/speech" \
-H "Content-Type: application/json" \
-d '{"model":"kokoclone","input":"Hello","voice":"af_bella","language_id":"en"}' \
--output speech.wav
Audio responses are WAV.
The chunked_voice_conversion function in core/chunked_convert.py handles memory automatically when converting long audio recordings:
vram_fraction parameter).mel_decoder Transformer has positional embeddings precomputed for 1,024 mel frames. Chunk windows are hard-capped below this limit (≈ 8.9s of source audio per chunk) with a 10% safety margin to prevent recomputation and quality degradation.api.py → FastAPI HTTP server (speech + clone)
app.py → Gradio Web Interface (two-tab UI)
cli.py → Command-line tool (tts and convert modes)
inference.py → Example API usage script
core/
├── cloner.py → Core TTS + voice cloning engine
└── chunked_convert.py → VRAM-aware chunked audio conversion
model/ → Downloaded Kokoro model weights (Auto-populates)
voice/ → Downloaded Kokoro voice bins (Auto-populates)
This project builds upon the incredible open-source work of:
Licensed under the Apache 2.0 License.