REST API
POST /text-to-speech converts text into speech and returns the complete audio, base64-encoded inside a JSON response. Use it for text that is known up front and when you need the whole file before you play or store it. To start playback before synthesis finishes, use the HTTP Streaming API or the WebSocket API. See Which API to use to compare all three.
Models
Both models share the same request format, limits and parameters. A speaker must belong to the model you request. See Voices for the full list and Bulbul for model details.
Quickstart
Set your API key as the SARVAM_API_KEY environment variable, then run one of these. Each saves the speech as a WAV file.
Always pass speaker explicitly. The Python SDK’s default speaker is not valid for current models, and the API default depends on model.
Request parameters
opus fails with a 400 at the default 22,050 Hz. Set speech_sample_rate to 8000, 16000, 24000 or 48000 when you use it. Unknown request fields are ignored without an error.
For how pace, pitch and loudness sound in practice, see the pace, pitch and loudness guides.
Response
The audio is base64 text, not binary. Decode it before you save or play it, and use a file extension that matches output_audio_codec (for example .mp3 for mp3).
In a browser, build a playable URL from the base64 string:
Customize the output
This example speaks Tamil text slightly faster, as 24 kHz MP3.
Errors
Errors return a JSON error object with message, code and request_id. The full code table, retry guidance and SDK exception reference are on Errors & Troubleshooting.
Handle errors in Python
See the API Reference for the full endpoint spec.
Need help? Contact us on Discord.