Voice Cloning API
The Voice Cloning API accepts reference audio, an exact transcript of the reference audio, and text to synthesize in one multipart request, then returns audio.
API overview
| Item | Value |
|---|---|
| Base URL | https://api.kitschlabs.com |
| Authentication | xi-api-key: <API_KEY> |
| Method | POST |
| Endpoint | /v1/voice-cloning/text-to-speech |
| Content-Type | multipart/form-data |
| Default output | mp3_44100_128 (audio/mpeg) |
| Additional output | wav_24000 (audio/wav) |
How do I authenticate?
Send your issued API key in the xi-api-key header. Store the real key in a
server environment variable or secret management service, and do not include
it in browsers, app bundles, or logs.
xi-api-key: <API_KEY>
How do I generate speech?
The reference audio must match reference_text exactly. The examples below
send the reference file and text to synthesize in one request.
- cURL
- Python
- JavaScript
curl --request POST \
"https://api.kitschlabs.com/v1/voice-cloning/text-to-speech?output_format=wav_24000" \
--header "xi-api-key: <API_KEY>" \
--form "text=This is the text to synthesize." \
--form "reference_text=This is the exact reference transcript." \
--form "reference_audio=@reference.wav" \
--form "language_code=en" \
--output speech.wav
import os
import requests
with open("reference.wav", "rb") as reference_audio:
response = requests.post(
"https://api.kitschlabs.com/v1/voice-cloning/text-to-speech",
params={"output_format": "wav_24000"},
headers={"xi-api-key": os.environ["KITSCH_API_KEY"]},
data={
"text": "This is the text to synthesize.",
"reference_text": "This is the exact reference transcript.",
"language_code": "en",
},
files={"reference_audio": reference_audio},
timeout=120,
)
response.raise_for_status()
with open("speech.wav", "wb") as audio_file:
audio_file.write(response.content)
import { readFile, writeFile } from "node:fs/promises";
const form = new FormData();
form.append("text", "This is the text to synthesize.");
form.append("reference_text", "This is the exact reference transcript.");
form.append("reference_audio", new Blob([await readFile("reference.wav")]), "reference.wav");
form.append("language_code", "en");
const response = await fetch(
"https://api.kitschlabs.com/v1/voice-cloning/text-to-speech?output_format=wav_24000",
{
method: "POST",
headers: {"xi-api-key": process.env.KITSCH_API_KEY},
body: form,
},
);
if (!response.ok) {
throw new Error(`${response.status}: ${await response.text()}`);
}
await writeFile("speech.wav", Buffer.from(await response.arrayBuffer()));
Which fields do I send?
| Field | Location | Type | Required | Description |
|---|---|---|---|---|
text | form | string | Yes | Text to synthesize |
reference_text | form | string | Yes | Exact transcript of the speech in the reference audio |
reference_audio | form | file | Yes | WAV, MP3, FLAC, or OGG file |
language_code | form | string | No | One of en, ko, ja, or zh |
instruct | form | string | No | Natural-language instructions for the speaking style |
speed | form | number | No | Speaking speed from 0.25 to 4 |
output_format | query | string | No | mp3_44100_128 or wav_24000 |
Reference audio can be up to 25 MiB and 20 seconds. In reference_text, include
only the words that can be heard. Do not include timestamps, speaker names,
subtitle markers, or translations.
How should I prepare reference audio?
- Use a clean, speech-only clip with one speaker.
- Avoid music, reverberation, background conversation, and strong noise.
- Do not cut off speech at the beginning or end of the clip.
- Choose a section that clearly contains the pronunciation and tone you need.
- Use only your own voice or a voice you have explicit permission to use.
Do not clone another person's voice without consent or use a cloned voice for impersonation, deception, or rights infringement.
Responses and errors
A successful request returns audio binary in the selected output_format.
Save the response to a file and log the x-kitsch-request-id.
| Status | Meaning | Recommended action |
|---|---|---|
400·422 | Required value, transcript, or file format error | Correct the request and reference audio |
401 | API key is missing or invalid | Check the key and xi-api-key header |
402 | Not enough available credits | Check the Billing status |
413 | Reference audio is too large | Reduce it to 25 MiB or less and retry |
429 | Account request limit exceeded | Follow Retry-After and apply backoff |
5xx | Temporary server error | Record the request ID and retry a limited number of times |