APIFleet Sign in

TTS API for voice agents: what to check before you pick one

A TTS API turns the text your language model writes into speech audio. For a voice agent on a phone line, pick one that streams audio before the reply is finished, returns 8 kHz mu-law or a format you can convert, stops when the caller interrupts and bills in a unit you can predict.

APIFleet team · · 8 min read

What is a TTS API in a voice agent?

A TTS API converts the text a language model writes into speech audio. In a cascading voice agent it is the third stage, after speech-to-text and the model. It must start sending audio before the whole reply exists, because the caller hears silence until the first audio arrives.

Speech-to-speech models have no separate TTS stage, so this guide applies to cascading assistants. The speech-to-speech models guide covers when to skip the stage, and the speech-to-text API guide covers the stage before it.

What should a TTS API do on a phone call?

Stream audio as text arrives, deliver the format the phone carrier needs, stop the moment a caller interrupts, report errors you can see and bill in a unit you can predict. Test all five on a real call, because a demo clip proves none of them.

The table adds three more checks that decide how a voice sounds and how you run it. Each row names something you can test on a call rather than read off a feature list.

Eight checks for a TTS API on a phone call
CheckWhy it mattersTest on a call
Text inWaiting for a full reply adds silenceTime the first word of a long answer
Phone audioA carrier line carries mu-law 8 kHzListen for artefacts on names and digits
InterruptionOld audio must not finishCut in at two seconds
Billing unitCost follows the unitCompare the call log with the invoice
Voice controlsPace and tone differ per vendorReplay one script per setting
PronunciationNames and numbers get misreadRead back a name and ten digits
FailureA rejected request sounds like silenceUse a wrong voice ID on a test assistant
CredentialsWhose account pays and rate-limitsCheck which key a call used

Does the TTS API stream text in and audio out?

Here, first audio means the time from the first text chunk handed to the provider to the first audio frame that comes back. Providers differ in how text goes in, and that sets the earliest moment a caller can hear anything.

APIFleet runs nine TTS adapters behind one interface: connect, push text, flush, end and abort. The table shows how each one takes text and returns audio; for measured first-audio timings of four providers, see the TTS models for phone calls post.

Two details matter in practice. Gemini streams on its 3.1 preview model but returns each phrase in one response on the 2.5 preview models, and Piper returns one complete WAV per request, so no chunk plays before that WAV is finished.

How text goes in and when audio can start, by provider
ProviderText goes in asAudio can start
ElevenLabsWebSocket streamAs frames arrive
CartesiaWebSocket streamAs frames arrive
DeepgramWebSocket streamAs frames arrive
TelnyxWebSocket streamAs frames arrive
SonioxWebSocket streamAs frames arrive
AzureOne HTTPS request per chunkAs the body arrives
PollyOne HTTPS request per chunkAs the body arrives
GeminiServer-sent events or one request per phraseDepends on the model
PiperHTTP to a self-hosted serverAfter the whole WAV

Which audio format does a phone call need?

Twilio documents that the Media Streams start message always reports audio/x-mulaw at 8000 Hz. APIFleet's phone leg is mu-law at 8 kHz on Telnyx and Twilio by default, while browser test sessions use 16-bit PCM at 24 kHz.

A provider that can return mu-law at 8 kHz lets APIFleet pass the audio through untouched. Any other output is converted in-process, and each conversion step is one more place for artefacts on names and digits, so listen for them on a real call.

The table describes what APIFleet's adapters request and do, not what each vendor could offer under another setup. For example, APIFleet's Telnyx adapter receives MP3 at 24 kHz, which it decodes before the conversion.

Phone audio each adapter gets and what APIFleet does with it
ProviderAudio APIFleet getsWhat APIFleet does
ElevenLabsmu-law 8 kHzPasses it through
Cartesiamu-law 8 kHzPasses it through
Deepgrammu-law 8 kHzPasses it through
Sonioxmu-law 8 kHzPasses it through
Azuremu-law 8 kHzPasses it through
PollyPCM at 8 kHzEncodes mu-law itself
TelnyxMP3 at 24 kHzDecodes, downsamples, encodes
GeminiPCM at 24 kHzDownsamples, encodes
PiperWAV, PCM16 monoResamples, encodes

What happens when a caller interrupts?

The provider has to stop now and discard anything queued, so old audio never finishes after the caller speaks. APIFleet's interface has one abort call for this, and each adapter implements it its own way.

ElevenLabs has no cancel frame, so APIFleet closes the socket and opens a new one for the next reply. Cartesia cancels the open generation, and Azure cancels the open request and drops its queued chunks.

Test it on a call. Ask for a long answer, interrupt after two seconds and check that the line goes quiet; the test voice agents guide has a script format for this.

How are TTS APIs billed?

Most providers bill by characters, some by tokens, and a self-hosted voice costs whatever your server costs. APIFleet logs a per-call estimate in the cost_tts field, so treat it as an estimate and reconcile it with the vendor invoice.

For character billing the formula is characters sent, divided by 1,000, times the price per 1,000 characters. Illustration, not a vendor price: at 0.05 dollars per 1,000 characters, a call where the assistant sends 3,000 characters costs 3 x 0.05 = 0.15 dollars of speech.

The APIFleet platform fee is separate: $0.03 per connected AI minute, billed per second, with provider, speech and carrier usage on top. On a 6-minute call that is $0.18 for the platform next to the illustrative 0.15 dollars of speech; the cost calculator and the voice agent costs guide break down the rest.

TTS billing units and how APIFleet logs them
Billing unitProvidersHow APIFleet logs it
CharactersAzure, Cartesia, Deepgram, ElevenLabsCharacters times a set rate
Characters by enginePollySeparate neural and generative rates
Characters by voice familyTelnyxA deliberate floor estimate
TokensGeminiInput and output tokens
Input and audio tokensSonioxEstimate from characters
Your own serverPiperAn operator-set estimate

Which voice controls matter on a phone call?

Controls differ by vendor and by voice, so APIFleet keeps them in one tts_settings object per assistant. ElevenLabs takes stability, similarity_boost, style and use_speaker_boost; Cartesia takes volume, emotion and pronunciation_dict_id, a dictionary you create through Cartesia's own API.

Azure takes rate, pitch and a style, and a voice that lacks the style ignores it. Piper takes noise_scale and noise_w_scale, and voice_speed is a plain multiplier that Gemini receives only as a pacing instruction.

Carriers normalise level hard on a phone leg, so treat Cartesia's volume as trim rather than a loudness control. Pronunciation matters more than tone for names and digits, so test those first.

What happens when the TTS API fails mid-call?

Replaying text is safe only until the first audio frame has reached the caller. After that a retry could repeat half a sentence, so APIFleet surfaces the error instead of retrying.

One automatic fallback exists, and only for Cartesia: with a Deepgram API key available, an error or no audio within the startup timeout (4,000 ms by default) replays that reply once on Deepgram. The trace records a tts_fallback_started event with the reason, and on a Telnyx or Twilio call a second failure ends the call with ended_reason tts_error.

For every other provider a voice error is fatal on a Telnyx or Twilio call: APIFleet hangs up with tts_error rather than leave a silent line. Test it with a wrong voice ID on a test assistant and read the call log.

How do you change the TTS provider on an assistant?

Switching is a configuration change, not a rebuild, and it is easy to reverse. Run the same script on each provider and compare, never trust one call.

The API reference lists every field, and the pricing page explains the platform fee. The Piper post shows the self-hosted path if you would rather run the voice yourself.

  1. Save the new provider's key with PUT /credentials/:provider, or use Piper, which takes no tenant credential.
  2. Send PATCH /assistants/:id with tts_provider, tts_model, tts_voice and any tts_settings, with If-Match set to the current revision.
  3. Write a test script with fictional data: read back a name, an address and a 10-digit number, then give a 40-word answer.
  4. Interrupt that answer after two seconds, stay silent for 8 seconds and use a wrong voice ID once on a test assistant.
  5. Run 20 or more calls per provider, because one call is noise, then compare cost_tts with the vendor usage page.
  6. Keep the old configuration, so you can PATCH back if the new voice loses on names and digits.
Diagram of one conversation: caller audio, speech and model, tools and context, then the spoken reply, with carrier charges listed separately

Continue with a practical next step

Frequently asked questions

What is TTS in voice AI?

TTS, or text to speech, is the stage that turns the text a language model writes into spoken audio. In a cascading voice agent it runs after speech-to-text and the model, and speech-to-speech models skip it.

What audio format does a phone call need from a TTS API?

Twilio documents that its Media Streams carry audio/x-mulaw at 8000 Hz, and APIFleet's Telnyx and Twilio phone leg is mu-law at 8 kHz by default. A provider that returns another format needs a conversion step before the audio reaches the caller.

Does a TTS API need to stream?

On a live call it should, because the caller hears nothing until the first audio arrives. Providers that take one request per chunk or return a whole file can still work, but the first sentence must be short.

How is a TTS API billed?

Usually per character, sometimes per token, and a self-hosted voice costs your own server time. APIFleet logs cost_tts as an estimate per call, so reconcile it with the vendor invoice.

What happens if the TTS API fails mid-call?

Before the first audio frame, APIFleet can replay text on one fallback, which exists only for Cartesia with a Deepgram key. After that, or for any other provider, the error ends a Telnyx or Twilio call with ended_reason tts_error.

Is there a Web Speech API?

Yes. MDN describes the Web Speech API as having a SpeechSynthesis interface for text to speech through the device's default synthesizer. It runs in a browser on the user's device, so it is not a server-side TTS API for phone calls.

Can I use my own TTS account with APIFleet?

Yes. Save your provider key per workspace with PUT /credentials/:provider. The API reference says anything a workspace has not configured falls back to the server's own keys, so check which key a call used.

How do I change the TTS provider on an assistant?

Send PATCH /assistants/:id with tts_provider, tts_voice and any tts_model or tts_settings, using If-Match with the current revision. Then run the same script on each provider, 20 or more calls each.

Sources and evidence

Prepared with AI assistance and checked against the linked evidence. Examples are illustrative unless explicitly documented as measured results.

Bring your next conversation.

Explore the API, or sign in to your existing workspace. New workspace access is currently limited; contact us to discuss your project.