Text to Speech
Turn text into natural speech with a project-scoped API key.
Type text, choose a voice, and hear the result without writing code.
GET STARTEDQuickstartCreate an API key and save your first generated audio file.
REFERENCEAPI detailsReview endpoints, request fields, and response handling.
When to use it
Quick start
Set the API address and key before running an example. See Get your API key if you do not have one yet.
export VUILABS_API_BASE_URL="https://api-global.vuilabs.ai"
export VUILABS_API_KEY="your-api-key"
- cURL
- JavaScript
- Python
curl --request POST \
--url "$VUILABS_API_BASE_URL/v1/text-to-speech" \
--header "X-API-Key: $VUILABS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"generate_text": "Your order is ready.",
"language": "en",
"speed": 1
}' \
--output speech.mp3
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({ generate_text: 'Your order is ready.', language: 'en', speed: 1 }),
});
if (!response.ok) throw new Error(await response.text());
await writeFile('speech.mp3', Buffer.from(await response.arrayBuffer()));
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={"generate_text": "Your order is ready.", "language": "en", "speed": 1},
)
response.raise_for_status()
with open("speech.mp3", "wb") as output:
output.write(response.content)
Use a specific voice
Set voice_id to a voice enabled for your project. Start with a short representative sentence before generating longer content.
- cURL
- JavaScript
- Python
curl --request POST \
--url "$VUILABS_API_BASE_URL/v1/text-to-speech" \
--header "X-API-Key: $VUILABS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"generate_text": "This request uses a specific voice.",
"voice_id": "your-approved-voice-id",
"language": "en",
"speed": 1
}' \
--output speech.mp3
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({
generate_text: 'This request uses a specific voice.',
voice_id: 'your-approved-voice-id',
language: 'en',
speed: 1,
}),
});
if (!response.ok) throw new Error(await response.text());
await writeFile('speech.mp3', Buffer.from(await response.arrayBuffer()));
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={
"generate_text": "This request uses a specific voice.",
"voice_id": "your-approved-voice-id",
"language": "en",
"speed": 1,
},
)
response.raise_for_status()
with open("speech.mp3", "wb") as output:
output.write(response.content)
API details
Request modes
POST /v1/text-to-speechWait for the complete audio response before playback or storage.
POST /v1/text-to-speech/streamConsume raw audio bytes as they become available.
Both endpoints use X-API-Key. The key determines the project, allowed capability, rate limit, and billing account.
Request headers
| Header | Required | Description |
|---|---|---|
X-API-Key | Yes | Your project API key. |
Content-Type | Yes | application/json |
JSON body
| Field | Type | Required | Use it for |
|---|---|---|---|
generate_text | string | Yes | The text to synthesize. Billing uses weighted character count. |
language | string | No | A language enabled for your TTS account. |
voice_id | string | No | An approved voice. Omit to use the configured default voice. |
speed | number | No | Delivery speed. Omit or use 0 for the provider default; negative values are rejected. |
emotion_class | string | No | An approved emotion preset, when supported by the selected voice. |
audio_format | string | No | An output format enabled for the selected voice and request mode. |
Streaming generation
The synchronous endpoint returns the complete file. The streaming endpoint returns HTTP chunked raw audio bytes in order; it is not SSE or a JSON event stream.
For both endpoints, HTTP 200 means the response body is audio, not JSON. The response Content-Type is the actual audio MIME type returned by the approved provider.