Generate speech in 5 minutes
Before you start
Create a project and an API key before making a request. See Get your API key for the complete steps.
export VUILABS_API_BASE_URL="https://api.vuilabs.ai"
export VUILABS_API_KEY="your-api-key"
Before running the request, replace YOUR_PROJECT_VOICE_ID with a voice available to this API key. It is not a shared demo voice; for a cloned voice, create it first with the Voice Cloning API.
Never share your API key or add it to public source code.
Generate your first audio
- cURL
- JavaScript
- Python
curl --fail-with-body --request POST \
--url "$VUILABS_API_BASE_URL/v1/text-to-speech" \
--header "X-API-Key: $VUILABS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"text": "Hello from VUILabs.",
"voice_id": "YOUR_PROJECT_VOICE_ID",
"language": "en",
"speed": 1
}' \
--dump-header speech.headers \
--output speech.response || { cat speech.response >&2; exit 1; }
if ! grep -Eiq '^content-type:[[:space:]]*audio/wav([[:space:];]|$)' speech.headers || [ ! -s speech.response ]; then
cat speech.response >&2
echo 'Expected a non-empty audio/wav response' >&2
exit 1
fi
mv speech.response speech.wav
import { writeFile } from 'node:fs/promises';
const response = await fetch(`${process.env.VUILABS_API_BASE_URL}/v1/text-to-speech`, {
method: 'POST',
headers: {
'X-API-Key': process.env.VUILABS_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: 'Hello from VUILabs.',
voice_id: 'YOUR_PROJECT_VOICE_ID',
language: 'en',
speed: 1,
}),
});
const contentType = (response.headers.get('content-type') || '').split(';')[0].trim().toLowerCase();
if (contentType === 'application/json') {
const result = await response.json();
throw new Error(`${result.error_code}: ${result.error_message}`);
}
if (!response.ok) throw new Error(`HTTP ${response.status}`);
if (contentType !== 'audio/wav') throw new Error(`Unexpected Content-Type: ${contentType}`);
const audio = Buffer.from(await response.arrayBuffer());
if (audio.length === 0) throw new Error('Empty audio response');
await writeFile('speech.wav', audio);
import os
import requests
response = requests.post(
f"{os.environ['VUILABS_API_BASE_URL']}/v1/text-to-speech",
headers={"X-API-Key": os.environ["VUILABS_API_KEY"]},
json={"text": "Hello from VUILabs.", "voice_id": "YOUR_PROJECT_VOICE_ID", "language": "en", "speed": 1},
)
content_type = response.headers.get("Content-Type", "").split(";")[0].strip().lower()
if content_type == "application/json":
result = response.json()
raise RuntimeError(f"{result['error_code']}: {result['error_message']}")
response.raise_for_status()
if content_type != "audio/wav":
raise RuntimeError(f"Unexpected Content-Type: {content_type}")
if not response.content:
raise RuntimeError("Empty audio response")
with open("speech.wav", "wb") as output:
output.write(response.content)
What happens next
The API returns raw audio bytes in an HTTP 200 response. Save the response to a file or pass it directly to an audio player.
Need to specify a voice? Choose a voice_id enabled for the current project.
Need the first audio chunk sooner? Switch to the streaming endpoint.
✓Need a different audio format? Both complete and Luna-TTS streaming requests support WAV (default) or raw PCM. Send audio_format: "pcm" for PCM and read the response audio metadata before playback.
Continue to Voices and output, or see the full Text to Speech API reference.