Skip to navigation

Which Text-to-Speech API to Use

View as Markdown

Sarvam offers three text-to-speech APIs for the same Bulbul models: REST, HTTP stream and WebSocket. They differ in how audio is delivered and how interactive the connection is. Voices, languages and parameters are the same on all three.

Pick in ten seconds

If you…Use
Have the full text and want one complete audio fileREST
Need a sample rate above 24,000 Hz (32,000, 44,100 or 48,000)REST
Have the full text and want playback or saving to start before synthesis finishesHTTP stream
Generate audio on a server, proxy it to a client, or run on serverless or edgeHTTP stream
Stream text from an LLM, or run a voice agent with many turnsWebSocket

The three APIs

How they compare

Delivery

RESTHTTP streamWebSocket
Audio arrivesAfter full synthesisAs it is generatedAs it is generated
Response formatJSON with base64 audioRaw binary audioJSON messages with base64 audio
Texts per connectionOneOneMany
SetupNoneNoneHandshake and config message
Auth headerapi-subscription-keyapi-subscription-keyApi-Subscription-Key

Limits and defaults

RESTHTTP streamWebSocket
Max text2,500 characters3,500 characters2,500 characters per message
Sample rates (Hz)8000, 16000, 22050, 24000, 32000, 44100, 480008000, 16000, 22050, 240008000, 16000, 22050, 24000
Default codecwavmp3mp3

All three accept the same codecs: wav, mp3, aac, flac, linear16, mulaw, alaw and opus. opus fails at the default 22,050 Hz, so set speech_sample_rate to 8000, 16000 or 24000 (and 48000 on REST).

Choosing between the two streaming APIs

Both streaming APIs return audio before the full clip is synthesized. The difference is control:

  • HTTP stream is one request in and one stream out. Choose it when you already have the whole text, or when WebSockets are not available.
  • WebSocket keeps one connection open, so you can send text in pieces as an LLM produces it and avoid reconnecting for each utterance. You also control buffering and flushing. Choose it for voice agents.