Skip to main content

Text to Speech API

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

The 1.5 defaults and updated CJK input and billing rules below apply to releases that include these changes. Earlier deployments keep their existing defaults and billing rules. Confirm model availability in the catalog for the API endpoint you call.

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.

Choose a model​

Modelmodel_idDeliveryVoice and parameter rules
Luna-TTS 1.5luna-tts-1.5 or latestSynchronous or streamingChinese, English, Japanese, and Korean; legacy and new 1.5 Luna system and cloned voices. Supports speed, volume, text_normalization, and the official expression tags below.
Luna-TTS (legacy)luna-ttsSynchronous or streamingSupports Luna system voices and cloned voices. Supports speed, text normalization, and expression tags.
Luna-TTS Characterluna-tts-characterSynchronous onlyUses only Character system voices. Supports volume, scene, and expressivity. Does not support cloned voices, speed, tags, or streaming. The synchronous HTTP API accepts but ignores text_normalization; omit this field.

Luna-TTS 1.5 supports Chinese, English, Japanese, and Korean. The fixed IDs are luna-tts-1.5 (version 1.5) and luna-tts (the legacy version); omitting model_id is equivalent to latest, currently Luna-TTS 1.5. Send luna-tts explicitly to keep using the legacy model. latest selects the latest enabled Luna version, currently 1.5, once for each accepted request. A failure never silently selects an older version.

Version 1.5 supports legacy Luna system and cloned voices plus voices introduced for 1.5. The legacy model cannot use a voice that requires 1.5. Call the List Voices API with the same model_id; select a returned voice_id. Incompatible combinations return HTTP 400, error 12913 (VOICE_MODEL_INCOMPATIBLE). Character is a separate model; select it explicitly.

Luna-TTS Character example​

{
"model_id": "luna-tts-character",
"text": "Welcome to VUI Labs.",
"voice_id": "jasper",
"volume": 0,
"scene": "normal"
}
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 '{
"model_id": "luna-tts-character",
"text": "Welcome to VUI Labs.",
"voice_id": "jasper",
"volume": 0,
"scene": "normal"
}' \
--output character.wav
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 '{
"text": "Your order is ready.",
"voice_id": "YOUR_PROJECT_VOICE_ID",
"language": "en",
"speed": 1
}' \
--output speech.wav

Specify a voice​

Pass a voice_id enabled for the current project. Test it with a short representative text before using it for longer content.

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 --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": "This request uses a specific voice.",
"voice_id": "YOUR_PROJECT_VOICE_ID",
"language": "en",
"speed": 1
}' \
--output 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: Luna-TTS only. 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: Luna-TTS and Character support -5 to 5 dB in steps of 0.1; the default is 0.
  • Character scene: Character only. normal is the default everyday delivery; whisper is a close whispering delivery.
  • Expression tags: Luna-TTS only. Put official tags below directly in text; Character does not support tags.
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

Only Luna-TTS supports streaming. Character requests are rejected.

Request headers​

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

JSON body​

FieldTypeRequiredDescription
textstringYesText to synthesize. Complete and streaming requests have a limit of 500 weighted input characters: Han characters (including extensions), Japanese hiragana/katakana, Korean Hangul, and ー/ー count as 2; CR/LF count as 0; other Unicode code points count as 1. For example, 250 kana or Hangul characters are accepted, while 251 are rejected with 400 / 10013 before synthesis or billing. The same input weights apply to legacy Luna-TTS, Luna-TTS 1.5, latest, and complete Character requests. Surrounding whitespace is removed before counting. Input admission and billing are calculated separately, as described below.
languagestringNoA language code enabled for the current TTS account.
voice_idstringYesA voice ID from the List Voices API compatible with the selected model; the request is rejected if omitted.
model_idstringNoluna-tts-1.5, luna-tts (fixed legacy), latest (default), or luna-tts-character.
speednumberNoLuna-TTS only; use 0.6–1.2; omission or 0 selects the default of 1.
volumenumberNoLuna-TTS and Character only; use -5 to 5 dB in steps of 0.1; default 0.
scenestringNoCharacter only: normal (default) or whisper.
expressivitystringNoCharacter only: normal (default) or strong.
text_normalizationbooleanNoLuna-TTS: true (default) enables text normalization before synthesis; false preserves the input text. Character accepts but ignores this field.
audio_formatstringNowav (default) or pcm. Both complete and streaming audio support PCM; streaming supports Luna-TTS only.

Use the voices and languages available to the current project in the Console.

Billing characters​

Legacy Luna-TTS, Luna-TTS 1.5, and synchronous Character use the same 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. Character does not support tags.

Billing uses the submitted original text after surrounding whitespace is removed, before text normalization. For example, あいうえお and 가나다라마 each bill 10 for all three models; [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 Luna responses, and synchronous Character responses, include X-Luna-Billable-Characters, the billable character count for the request. X-Luna-Billing-Rule-Version identifies the counting rule for diagnostics; clients should not hard-code its value or use it to select a model.

Choose a model using the public model_id values above. The same character weights do not change model prices. USD billing and Creator credits use separate accounts. Historical usage keeps its original price and counting rule; later changes to latest do not recalculate it.

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. Character ignores this field. Its synchronous HTTP API accepts boolean true or false, but neither value controls text normalization for Character. Omit this field for Character requests.

{
"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:

{
"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", "luna-tts", and "latest". It returns ordered audio bytes in the HTTP response body, not SSE, JSON events, or base64. Character does not support this endpoint.

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 --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",
"text": "Your order is ready.",
"voice_id": "YOUR_PROJECT_VOICE_ID",
"audio_format": "pcm"
}' \
--dump-header speech-pcm.headers \
--output 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.