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)

ParameterTypeDescription
modelrequiredstringTTS model ID. Call GET /v1/models and pick a model with type TTS.
inputrequiredstringText to synthesize. Max 2500 chars (bulbul:v3) or 1500 chars (bulbul:v2).
voicerequiredstringSpeaker name. See the Voices section below for available options.
response_formatstringAudio 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

bash
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

tts.py
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

tts.ts
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)

tts-browser.js
// 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();
Tip: Try voices interactively in the Portal Playground → TTS tab before hardcoding a voice in your application.

Error codes

401
Unauthorized
Missing or invalid API key.
402
Insufficient balance
Wallet is empty. Top up credits before retrying.
422
Validation error
Missing required field (model, input, or voice) or unsupported format.
502
Upstream error
The TTS service returned an error. Retry the request.