# TTS API for voice agents: how to choose one | APIFleet

> A TTS API for voice agents must stream audio, return 8 kHz mu-law for phone calls and bill in a unit you can predict. Eight checks and a provider table.

Canonical URL: https://apifleet.dev/blog/tts-api-voice-agents
Last updated: 2026-11-29
Markdown Mirror URL: https://apifleet.dev/blog/tts-api-voice-agents.md
LLM index: https://apifleet.dev/llms.txt
MCP discovery: https://apifleet.dev/.well-known/mcp.json

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 · 29 November 2026 · 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

| Check | Why it matters | Test on a call |
| --- | --- | --- |
| Text in | Waiting for a full reply adds silence | Time the first word of a long answer |
| Phone audio | A carrier line carries mu-law 8 kHz | Listen for artefacts on names and digits |
| Interruption | Old audio must not finish | Cut in at two seconds |
| Billing unit | Cost follows the unit | Compare the call log with the invoice |
| Voice controls | Pace and tone differ per vendor | Replay one script per setting |
| Pronunciation | Names and numbers get misread | Read back a name and ten digits |
| Failure | A rejected request sounds like silence | Use a wrong voice ID on a test assistant |
| Credentials | Whose account pays and rate-limits | Check 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

| Provider | Text goes in as | Audio can start |
| --- | --- | --- |
| ElevenLabs | WebSocket stream | As frames arrive |
| Cartesia | WebSocket stream | As frames arrive |
| Deepgram | WebSocket stream | As frames arrive |
| Telnyx | WebSocket stream | As frames arrive |
| Soniox | WebSocket stream | As frames arrive |
| Azure | One HTTPS request per chunk | As the body arrives |
| Polly | One HTTPS request per chunk | As the body arrives |
| Gemini | Server-sent events or one request per phrase | Depends on the model |
| Piper | HTTP to a self-hosted server | After 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

| Provider | Audio APIFleet gets | What APIFleet does |
| --- | --- | --- |
| ElevenLabs | mu-law 8 kHz | Passes it through |
| Cartesia | mu-law 8 kHz | Passes it through |
| Deepgram | mu-law 8 kHz | Passes it through |
| Soniox | mu-law 8 kHz | Passes it through |
| Azure | mu-law 8 kHz | Passes it through |
| Polly | PCM at 8 kHz | Encodes mu-law itself |
| Telnyx | MP3 at 24 kHz | Decodes, downsamples, encodes |
| Gemini | PCM at 24 kHz | Downsamples, encodes |
| Piper | WAV, PCM16 mono | Resamples, 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 unit | Providers | How APIFleet logs it |
| --- | --- | --- |
| Characters | Azure, Cartesia, Deepgram, ElevenLabs | Characters times a set rate |
| Characters by engine | Polly | Separate neural and generative rates |
| Characters by voice family | Telnyx | A deliberate floor estimate |
| Tokens | Gemini | Input and output tokens |
| Input and audio tokens | Soniox | Estimate from characters |
| Your own server | Piper | An 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](https://apifleet.dev/content/voice-agent-workflow.svg)

## Continue with a practical next step

- [APIFleet API reference for assistants and credentials](https://apifleet.dev/docs/api)
- [APIFleet pricing: the platform fee and what it excludes](https://apifleet.dev/pricing)
- [TTS models for phone calls: measured first-audio timings](https://apifleet.dev/blog/tts-models-phone-calls)
- [Speech-to-text API guide for the stage before TTS](https://apifleet.dev/blog/speech-to-text-api-voice-agents)
- [Speech-to-speech models and when to skip the TTS stage](https://apifleet.dev/blog/speech-to-speech-models)
- [Voice agent costs: the per-minute breakdown by component](https://apifleet.dev/blog/voice-agent-costs)
- [Voice agent cost calculator for your call volume](https://apifleet.dev/tools/voice-agent-cost-calculator)
- [Voice agent testing guide: scripts and scenarios](https://apifleet.dev/blog/test-voice-agents)
- [Piper TTS guide for a self-hosted voice](https://apifleet.dev/blog/piper-tts)
- [Voice agent evaluation noise: why one test call is not enough](https://apifleet.dev/blog/voice-agent-evaluation-noise)

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

- [Twilio Media Streams: WebSocket messages](https://www.twilio.com/docs/voice/media-streams/websocket-messages) · observed 2026-11-29
- [MDN: Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API) · observed 2026-11-29

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

## Next on your reading list.

[TTS Models for Phone Calls: Production Data Guide](https://apifleet.dev/blog/tts-models-phone-calls)[Speech-to-text API for voice agents: best picks](https://apifleet.dev/blog/speech-to-text-api-voice-agents)[Piper TTS on phone calls: latency and cost guide](https://apifleet.dev/blog/piper-tts)

## Related

- [APIFleet](https://apifleet.dev/)
- [Documentation](https://apifleet.dev/docs)
- [Pricing](https://apifleet.dev/pricing)
