Text to Speech API
Convert text into natural speech using a project-scoped API key.
Use cases
Quick start
Set the API base URL and API key first. If you do not have a key, see Get your API key.
All endpoints use the X-API-Key request header. The API key determines the account, project, available capabilities, rate limits, and billing attribution.
export VUILABS_API_BASE_URL="https://api.vuilabs.ai"
export VUILABS_API_KEY="your-api-key"
Before running an example, use the List Voices API with your selected model_id and replace YOUR_PROJECT_VOICE_ID with a returned voice_id. It is deliberately not a shared demo voice. For a cloned voice, first create it with the Voice Cloning API, then use the same ID here.
Model
| Model | model_id | Delivery | Voice and parameter rules |
|---|---|---|---|
| Luna-TTS 1.5 | luna-tts-1.5 | Synchronous or streaming | Chinese, English, Japanese, and Korean; Luna system voices, public community voices, cloned voices, and multi-style voices. Supports speed, text_normalization, and the official expression tags below; volume is available for synchronous requests only. Multi-style voices additionally support scene and expressivity. |
Use luna-tts-1.5. Luna-TTS 1.5 supports Chinese, English, Japanese, and Korean. You must explicitly specify model_id in every synthesis request.
Call the List Voices API with the same model_id; select a returned voice_id. Multi-style voices are identified by multi_style: true in the voice list.
Multi-style voice example
Multi-style voices accept scene and expressivity on Luna-TTS 1.5; both are optional and default to normal. Pass whisper or strong to select the corresponding style combination. These fields are available only for multi-style voices; ordinary voices that pass either field with a non-empty value get an error (HTTP 400, code 10001).
| scene | expressivity | Delivery |
|---|---|---|
normal (default) | normal (default) | Everyday conversation, standard delivery |
normal | strong | Everyday conversation, enhanced delivery |
whisper | normal | Close whispering, standard delivery |
whisper | strong | Close whispering, enhanced delivery |
Synchronous request (ryder, whisper + strong):
{
"model_id": "luna-tts-1.5",
"text": "Welcome to VUI Labs.",
"voice_id": "ryder",
"volume": 0,
"scene": "whisper",
"expressivity": "strong"
}
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 '{
"model_id": "luna-tts-1.5",
"text": "Welcome to VUI Labs.",
"voice_id": "ryder",
"volume": 0,
"scene": "whisper",
"expressivity": "strong"
}' \
--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
Streaming request (POST /v1/text-to-speech/stream):
curl --fail-with-body --silent --show-error --no-buffer \
--request POST \
--url "$VUILABS_API_BASE_URL/v1/text-to-speech/stream" \
--header "X-API-Key: $VUILABS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model_id": "luna-tts-1.5",
"text": "Welcome to VUI Labs.",
"voice_id": "ryder",
"scene": "whisper",
"expressivity": "strong"
}' \
--dump-header speech-stream.headers \
--output speech-stream.response || { cat speech-stream.response >&2; exit 1; }
if ! grep -Eiq '^content-type:[[:space:]]*audio/wav([[:space:];]|$)' speech-stream.headers || [ ! -s speech-stream.response ]; then
cat speech-stream.response >&2
echo 'Expected a non-empty audio/wav response' >&2
exit 1
fi
mv speech-stream.response speech-stream.wav
- 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 '{
"model_id": "luna-tts-1.5",
"text": "Your order is ready.",
"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({ model_id: 'luna-tts-1.5', text: 'Your order is ready.', 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={"model_id": "luna-tts-1.5", "text": "Your order is ready.", "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)
Specify a voice
Pass a voice_id returned by the List Voices API for luna-tts-1.5, including system voices, available public community voices, and your organization's personal voices. Test it with a short representative text before using it for longer content.
Public community voices work directly with both synchronous (POST /v1/text-to-speech) and streaming (POST /v1/text-to-speech/stream) requests when model_id is set to luna-tts-1.5. If a community voice becomes private, is removed, or is disabled by the platform, new requests from other organizations return HTTP 400 with error code 12950 (for streaming requests, before audio starts). List voices again to choose an available ID. As long as the voice has not been deleted, the owning organization can still use the same voice_id for synthesis.
When selecting a custom voice, the member associated with the API key must have active access to its organization. A deactivated or removed member causes HTTP 403 with error_code: 10004 for synchronous and streaming requests. The streaming request is rejected before audio starts. Restore access before retrying; see error codes.
- 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 '{
"model_id": "luna-tts-1.5",
"text": "This request uses a specific voice.",
"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({
model_id: 'luna-tts-1.5',
text: 'This request uses a specific voice.',
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={
"model_id": "luna-tts-1.5",
"text": "This request uses a specific voice.",
"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)
Control delivery
Start with a short representative sentence, then adjust one control at a time so the result is easy to compare.
- Speed: Use a value from
0.6to1.2; omission or0selects the default of1. Version 1.5 adjusts the generated audio’s speed while preserving pitch. - Volume: Synchronous requests support
-5to5dB in steps of0.1; the default is0. Streaming requests do not provide avolumeparameter. - Scene (multi-style voices):
normalfor everyday conversation (default),whisperfor close whispering; ordinary voices get an error (HTTP400, code10001). - Expressivity (multi-style voices):
normalfor standard delivery (default),strongfor enhanced delivery; ordinary voices get an error (HTTP400, code10001). - Expression tags: Put the official tags below directly in
text, keeping the square brackets, e.g.Welcome back. [laughs].
| Official tags | Official tags | Official tags |
|---|---|---|
[laughs] | [chuckles] | [gasps] |
[sighs] | [inhales] | [breath] |
[exhale] | [coughs] | [clears throat] |
[sniffles] | [snorts] | [hisses] |
[tsks] | [groans] |
API details
Request modes
POST /v1/text-to-speechPlay or save the audio after receiving the complete file.
POST /v1/text-to-speech/streamBegin consuming audio as it is generated.
Request headers
| Header | Required | Description |
|---|---|---|
X-API-Key | Yes | Project API key |
Content-Type | Yes | application/json |
JSON body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to synthesize. Up to 500 weighted input characters. |
language | string | No | A language code enabled for the current TTS account. |
voice_id | string | Yes | A voice ID from the List Voices API compatible with the selected model, including system voices, available public community voices, and personal voices; the request is rejected if omitted. |
model_id | string | Yes | luna-tts-1.5. |
speed | number | No | Use 0.6–1.2; omission or 0 selects the default of 1. |
volume | number | No | Synchronous requests only; use -5 to 5 dB in steps of 0.1; default 0. Omit for streaming requests. |
scene | string | No | Multi-style voices only. normal for everyday conversation (default), whisper for close whispering; ordinary voices get an error (HTTP 400, code 10001). |
expressivity | string | No | Multi-style voices only. normal for standard delivery (default), strong for enhanced delivery; ordinary voices get an error (HTTP 400, code 10001). |
text_normalization | boolean | No | Luna-TTS: true (default) enables text normalization before synthesis; false preserves the input text. |
audio_format | string | No | wav (default) or pcm. Both complete and streaming audio support PCM. |
Use the voices and languages available to the current project in the Console.
Input character limit
Synchronous and streaming requests accept up to 500 weighted characters per request.
Trim leading and trailing whitespace, then count Unicode code points. Han characters (including extensions), hiragana, katakana, Hangul, and ー and ー each count as 2. CR and LF count as 0. Every other code point counts as 1.
Billing characters
Luna-TTS 1.5 uses the following Developer API billing character weights. Within the ranges below, Chinese, Japanese, and Korean characters count as 2 billing characters. Basic Han U+4E00–U+9FFF, Japanese hiragana/katakana, Korean Hangul, and the long-vowel marks ー/ー count as 2; other Unicode code points count as 1; CR/LF are excluded. Control-tag text, brackets, and internal spaces count for Luna models.
Billing uses the submitted original text after surrounding whitespace is removed, before text normalization. For example, あいうえお and 가나다라마 each bill 10; [laughs]你好呀 bills 14 for Luna. All Han characters count as 2 for input admission, while Han extensions count as 1 for billing. Use the billing quantity returned for the request rather than the input-limit counter.
Successful synchronous and streaming responses include X-Luna-Billable-Characters, the billable character count for the request.
USD billing and Creator credits use separate accounts. Historical usage keeps its original price and counting rule.
Text normalization
Only Luna-TTS applies text_normalization. Send a JSON boolean, not a quoted string. true is the default and normalizes the text before synthesis; explicitly send false to preserve the input text. Every streaming segment uses the same setting.
{
"model_id": "luna-tts-1.5",
"text": "Your order total is $36.50.",
"voice_id": "YOUR_PROJECT_VOICE_ID",
"text_normalization": true
}
For Luna-TTS, omit text_normalization or set it to true to normalize text before synthesis. Explicitly set it to false to preserve the input text. In Console Speech Synthesis, the Text Normalization toggle sends this choice with each generation.
Synchronous response formats
POST /v1/text-to-speech returns a complete WAV file with Content-Type: audio/wav when audio_format is omitted or set to wav. For raw PCM, send "audio_format": "pcm" in the JSON body:
{
"model_id": "luna-tts-1.5",
"text": "Your order is ready.",
"voice_id": "YOUR_PROJECT_VOICE_ID",
"audio_format": "pcm"
}
The PCM response contains signed 16-bit little-endian audio (PCM_S16LE) without a WAV header and uses Content-Type: audio/pcm. Save it with a .pcm extension and configure playback using these response headers:
| Response header | Meaning |
|---|---|
X-Audio-Sample-Rate | Actual sample rate in Hz. |
X-Audio-Channels | Actual number of channels. |
X-Audio-Bit-Depth | Bit depth; 16 for PCM. |
The sample rate and channel count preserve the synthesized audio; the API does not resample it. Do not assume a fixed 24000 Hz rate or mono audio. WAV and PCM work with the voices and models available to the synchronous endpoint. Other formats are rejected.
Streaming generation
POST /v1/text-to-speech/stream supports model_id: "luna-tts-1.5". It returns ordered audio bytes in the HTTP response body, not SSE, JSON events, or base64. Omit volume: streaming requests do not support volume adjustment.
audio_format | Content-Type | Audio bytes |
|---|---|---|
Omitted or wav | audio/wav | WAV audio, including its container header; use a WAV-capable decoder. |
pcm | audio/pcm | Raw signed 16-bit little-endian PCM (PCM16LE), without a WAV header. |
For PCM, configure your decoder using the response headers. The sample rate and channel count reflect the generated audio; do not hard-code a sample rate.
| PCM response header | Meaning |
|---|---|
X-Audio-Sample-Rate | Sample rate in Hz. |
X-Audio-Channels | Number of channels. |
X-Audio-Bit-Depth | Bits per sample; 16 for PCM16LE. |
The PCM stream contains audio samples only, including when speech is generated in multiple segments. Consume bytes in order. HTTP chunk boundaries are not audio frame boundaries: retain any incomplete frame for the next read.
Save a PCM stream
Use the API base URL and key configured above, and replace YOUR_PROJECT_VOICE_ID with an enabled Luna-TTS voice. The command saves the raw samples and response headers separately.
curl --fail-with-body --silent --show-error --no-buffer \
--request POST \
--url "$VUILABS_API_BASE_URL/v1/text-to-speech/stream" \
--header "X-API-Key: $VUILABS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model_id": "luna-tts-1.5",
"text": "Your order is ready.",
"voice_id": "YOUR_PROJECT_VOICE_ID",
"audio_format": "pcm"
}' \
--dump-header speech-pcm.headers \
--output speech.response || { cat speech.response >&2; exit 1; }
if ! grep -Eiq '^content-type:[[:space:]]*audio/pcm([[:space:];]|$)' speech-pcm.headers || [ ! -s speech.response ]; then
cat speech.response >&2
echo 'Expected a non-empty audio/pcm response' >&2
exit 1
fi
mv speech.response speech.pcm
Read speech-pcm.headers before playback: a .pcm file does not store its sample rate or channel count. Saving bytes is not a playback example.
Before audio starts, failures return the normal JSON error body. Some business failures, including 10023 (no synthesizable content), use HTTP 200; inspect Content-Type, succeed, and error_code before treating the body as audio. Once streaming has started, a failure interrupts the audio response; no JSON error is appended to the audio. A 200 status alone does not prove the stream completed successfully. Preserve transport errors and handle incomplete playback.
Successful responses from both endpoints contain audio with an audio Content-Type. A JSON response can still be a business failure at HTTP 200, for example error_code: 10023. Check the MIME type and JSON error fields before playback or saving.