Documentation
Text-to-Speech
POST /v1/audio/speech converts text into spoken audio.
Use it when
- You need voice playback in an app
- You want narration, announcements, or assistant voice output
Code examples
1curl -X POST https://api.navy/v1/audio/speech \
2 -H "Authorization: Bearer sk-navy-YOUR_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "gpt-4o-mini-tts",
6 "voice": "alloy",
7 "input": "Welcome to the NavyAI platform."
8 }' \
9 --output speech.mp3Parameters
model(string, required) —tts-1,tts-1-hd,eleven_v3,gpt-4o-mini-tts,gemini-2.5-flash-preview-ttsinput(string, required) — Text to convert (max 4096 chars for ElevenLabs)voice(string, required) — Voice ID. OpenAI:alloy,ash,coral,echo,fable,nova,onyx,sage,shimmer. ElevenLabs:alice,aria,bill,brian,callum,charlie,charlotte,chris,daniel,eric,george,jessica,laura,liam,lily,matilda,river,sarah,will. Gemini:Puck,Charon,Kore,Fenrir,Aoedespeed(number, optional) — 0.25–4.0 (OpenAI models only)response_format(string, optional) —mp3,opus,aac,flac(OpenAI only). ElevenLabs always returnsaudio/mpeg; Gemini always returnsaudio/wav.stability(number, optional) — ElevenLabs only. 0.0–1.0, defaults to0.5. Lower values are more expressive, higher values are more consistent.similarity_boost(number, optional) — ElevenLabs only. 0.0–1.0, defaults to0.5. Higher values stick closer to the cloned voice.with-timestamps(boolean, optional) — ElevenLabs only. Iftrue, returns JSON with per-character timestamps instead of raw audio. Useful for karaoke-style highlights.pronunciation_dictionary(array, optional) — Rules controlling how specific words are pronounced. See below.
Pronunciation dictionaries
Names, acronyms, and loanwords are the usual reason a generation comes out wrong. Pass a pronunciation_dictionary to fix them. NavyAI applies the rules to your text before sending it upstream, so there is nothing to upload, register, or manage — the rules travel with each request.
Bash
1curl -X POST https://api.navy/v1/audio/speech \
2 -H "Authorization: Bearer sk-navy-YOUR_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "eleven_flash_v2",
6 "voice": "alice",
7 "input": "Drive through Claughton and buy a tomato.",
8 "pronunciation_dictionary": [
9 { "string_to_replace": "Claughton", "type": "alias", "alias": "Cloffton" },
10 { "string_to_replace": "tomato", "type": "phoneme",
11 "alphabet": "cmu-arpabet", "phoneme": "T AH0 M EY1 T OW2" }
12 ]
13 }' \
14 --output speech.mp3Each rule is an object:
string_to_replace(string, required) — The word or phrase to match. Max 200 characters.type(string, required) —aliasorphoneme.alias(string, required for alias rules) — A plain-text respelling, e.g.ClofftonforClaughton. No phonetic knowledge needed.phoneme(string, required for phoneme rules) — The pronunciation itself.phis accepted as an alias for this field.alphabet(string, required for phoneme rules) —ipaorcmu-arpabet.case_sensitive(boolean, optional) — Defaults totrue.word_boundaries(boolean, optional) — Defaults totrue, socatwill not match insideconcatenate.
Max 100 rules per request. When two rules overlap, the longer string_to_replace wins, and a rule never re-matches text that another rule already produced.
Pronunciation model support
- Alias rules work on every text-to-speech model, including OpenAI and Gemini.
- Phoneme rules work on
eleven_flash_v2andeleven_turbo_v2(both alphabets) and oneleven_v3(ipaonly). - On any other model, phoneme rules are skipped, the original word is left exactly as written, and the response carries an
X-Navy-Pronunciation-Warningsheader naming the reason. The warnings also appear in the JSON body whenwith-timestampsis set, and on the job object for async requests. Alias rules in the same request still apply.
Notes
- Response content-type depends on the provider: OpenAI uses the
response_formatyou set, ElevenLabs returnsaudio/mpeg(or JSON whenwith-timestampsis true), Gemini returnsaudio/wav(24 kHz mono PCM in a WAV container). - ElevenLabs caps
inputat 4,096 characters. Longer text must be chunked client-side. Phoneme rules expand into inline tags that count toward the same cap. - Long generations can outlive the connection and return a
524. See the Async Text-to-Speech Jobs page — the audio is generated off the request and kept for you instead of being lost. - Keep text chunks moderate if you need responsive playback.