Skip to main content

Text to Speech API

Convert text into natural speech using a project-scoped API key.

Use cases​

Voiceovers and narrationUse for product demos, videos, stories, and long-form content.
Conversational experiencesGenerate assistant replies as audio, or stream them as they are generated.
Accessibility and IVRRead content aloud and build phone menus and voice guidance.
Product notificationsTurn alerts, status updates, and personalized messages into speech.

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​

Modelmodel_idDeliveryVoice and parameter rules
Luna-TTS 1.5luna-tts-1.5Synchronous or streamingChinese, 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).

sceneexpressivityDelivery
normal (default)normal (default)Everyday conversation, standard delivery
normalstrongEveryday conversation, enhanced delivery
whispernormalClose whispering, standard delivery
whisperstrongClose 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 --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

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 --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

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.6 to 1.2; omission or 0 selects the default of 1. Version 1.5 adjusts the generated audio’s speed while preserving pitch.
  • Volume: Synchronous requests support -5 to 5 dB in steps of 0.1; the default is 0. Streaming requests do not provide a volume parameter.
  • Scene (multi-style voices): normal for everyday conversation (default), whisper for close whispering; ordinary voices get an error (HTTP 400, code 10001).
  • Expressivity (multi-style voices): normal for standard delivery (default), strong for enhanced delivery; ordinary voices get an error (HTTP 400, code 10001).
  • Expression tags: Put the official tags below directly in text, keeping the square brackets, e.g. Welcome back. [laughs].
Official tagsOfficial tagsOfficial tags
[laughs][chuckles][gasps]
[sighs][inhales][breath]
[exhale][coughs][clears throat]
[sniffles][snorts][hisses]
[tsks][groans]

API details​

Request modes​

COMPLETE AUDIOPOST /v1/text-to-speech

Play or save the audio after receiving the complete file.

LUNA-TTS STREAMING AUDIOPOST /v1/text-to-speech/stream

Begin consuming audio as it is generated.

Request headers​

HeaderRequiredDescription
X-API-KeyYesProject API key
Content-TypeYesapplication/json

JSON body​

FieldTypeRequiredDescription
textstringYesText to synthesize. Up to 500 weighted input characters.
languagestringNoA language code enabled for the current TTS account.
voice_idstringYesA 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_idstringYesluna-tts-1.5.
speednumberNoUse 0.6–1.2; omission or 0 selects the default of 1.
volumenumberNoSynchronous requests only; use -5 to 5 dB in steps of 0.1; default 0. Omit for streaming requests.
scenestringNoMulti-style voices only. normal for everyday conversation (default), whisper for close whispering; ordinary voices get an error (HTTP 400, code 10001).
expressivitystringNoMulti-style voices only. normal for standard delivery (default), strong for enhanced delivery; ordinary voices get an error (HTTP 400, code 10001).
text_normalizationbooleanNoLuna-TTS: true (default) enables text normalization before synthesis; false preserves the input text.
audio_formatstringNowav (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 headerMeaning
X-Audio-Sample-RateActual sample rate in Hz.
X-Audio-ChannelsActual number of channels.
X-Audio-Bit-DepthBit 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_formatContent-TypeAudio bytes
Omitted or wavaudio/wavWAV audio, including its container header; use a WAV-capable decoder.
pcmaudio/pcmRaw 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 headerMeaning
X-Audio-Sample-RateSample rate in Hz.
X-Audio-ChannelsNumber of channels.
X-Audio-Bit-DepthBits 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.

TREAT THE RESPONSE AS AUDIO

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.