API Reference
POST/v1/audio/speech
Text-to-Speech
Convert text to natural-sounding speech. Returns audio as a binary stream in your chosen format. Supports 11 Indic languages with 43+ voices via Sarvam AI (bulbul:v3).
Request body (JSON)
| Parameter | Type | Description |
|---|
modelrequired | string | TTS model ID. Call GET /v1/models and pick a model with type TTS. |
inputrequired | string | Text to synthesize. Max 2500 chars (bulbul:v3) or 1500 chars (bulbul:v2). |
voicerequired | string | Speaker name. See the Voices section below for available options. |
response_format | string | Audio format: "mp3" (default), "wav", "opus", "flac", "aac", "pcm". |
Sarvam TTS models
bulbul:v3Latest
43+ voices, pace (0.5–2.0), temperature (0.01–2.0), speech_sample_rate, enable_preprocessing. Max 2500 chars.bulbul:v2Legacy
7 voices, pitch (−0.75–0.75), loudness (0.3–3.0), pace (0.3–3.0). Max 1500 chars.Available voices (bulbul:v3)
Pass the speaker name as the voice field. Available voices depend on the model route configured for your account. Common Sarvam voices:
ananyaF
manishaF
vidyaF
aryanM
abhilashM
karunM
hiteshM
neelM
pavithraF
maitreyiF
divyaF
amolM
Response
Returns the raw audio binary. The Content-Type matches the format requested:
mp3audio/mpeg
wavaudio/wav
opusaudio/ogg
flacaudio/flac
aacaudio/aac
pcmaudio/wav (linear16)
curl
curl https://api.inferexai.in/v1/audio/speech \
-H "Authorization: Bearer sk-live-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-voice",
"input": "नमस्ते! मैं आपकी कैसे मदद कर सकता हूँ?",
"voice": "ananya",
"response_format": "mp3"
}' \
--output audio.mp3
Python
from inferexai import InferexAI
from pathlib import Path
client = InferexAI(api_key="sk-live-your-key")
response = client.audio.speech.create(
model="tts-voice", # use a TTS model ID from /v1/models
voice="ananya",
input="नमस्ते! मैं आपकी कैसे मदद कर सकता हूँ?",
response_format="mp3",
)
Path("output.mp3").write_bytes(response.content)
Node.js
import InferexAI from "inferexai";
import fs from "fs";
const client = new InferexAI({ apiKey: "sk-live-your-key" });
const mp3 = await client.audio.speech.create({
model: "tts-voice",
voice: "ananya",
input: "नमस्ते! मैं आपकी कैसे मदद कर सकता हूँ?",
response_format: "mp3",
});
fs.writeFileSync("output.mp3", Buffer.from(await mp3.arrayBuffer()));
Browser / Edge (fetch)
// Fetch + Web Audio API (browser / edge runtime)
const response = await fetch(
"https://api.inferexai.in/v1/audio/speech",
{
method: "POST",
headers: {
"Authorization": "Bearer sk-live-your-key",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "tts-voice",
voice: "ananya",
input: "Hello from the browser!",
response_format: "mp3",
}),
}
);
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const audio = new Audio(url);
audio.play();
Error codes
401Unauthorized
Missing or invalid API key.
402Insufficient balance
Wallet is empty. Top up credits before retrying.
422Validation error
Missing required field (model, input, or voice) or unsupported format.
502Upstream error
The TTS service returned an error. Retry the request.