API Reference
POST/v1/audio/speech
Text-to-Speech
Convert text to natural-sounding speech across Indic languages and English, with 40+ voices. Returns audio in your chosen format, or a low-latency stream for real-time and voice-agent use.
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. The maximum length varies by model; see GET /v1/models. |
voicerequired | string | Voice name. See the Voices section below for available options. |
response_format | string | Audio format: "mp3" (default), "wav", "opus", "flac", "aac", "pcm" (raw S16LE), "mulaw" (G.711 8kHz, for telephony). |
stream_format | string | Set to "sse" to stream audio as OpenAI speech events (speech.audio.delta / speech.audio.done). See Streaming below. |
sample_rate | integer | Output sample rate in Hz for streamed/raw PCM (e.g. 24000, 16000, 8000). "mulaw" is always 8 kHz. |
Optional tuning parameters
These are accepted where the selected model supports them and ignored otherwise, so it is safe to send them. Which apply to a given model is published by GET /v1/models.
speedSpeech rate multiplier. 1.0 is normal; lower is slower.
temperatureExpressiveness / variation in delivery, where supported.
sample_rateOutput sample rate in Hz for raw/streamed PCM.
Available voices
Pass the voice name as the voice field. The voices available to your account are published by GET /v1/models under each TTS model. Common 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/L16 (raw signed 16-bit PCM)
mulawaudio/basic (G.711 µ-law, 8 kHz)
Streaming (low latency)
For real-time and voice-agent use, stream audio so playback starts before synthesis finishes. There are two ways to consume it, and the audio is normalized to one format either way — raw signed 16-bit PCM (pcm), or 8 kHz G.711 µ-law (mulaw) for a telephony leg.
stream_format: "sse"OpenAI speech events — speech.audio.delta frames of base64 audio, then speech.audio.done. Best for browser and SDK clients that understand the event stream.
raw PCM (no flag)Request a raw response_format (pcm/mulaw) and read the response body incrementally. This is what pipecat and LiveKit pipelines do out of the box — no client change needed. Transparent to a buffering client, which receives the same bytes.
Server-sent events:
# Stream audio as OpenAI speech events (SSE).
# Each "speech.audio.delta" carries a base64 PCM chunk; "speech.audio.done"
# ends the stream and declares the format and sample rate produced.
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": "pcm",
"sample_rate": 24000,
"stream_format": "sse"
}'
Raw PCM (pipecat / LiveKit style):
# Voice-agent frameworks (pipecat, LiveKit) read raw PCM progressively —
# no special flag. Request a raw PCM format and read the body as a stream;
# audio arrives in ~milliseconds instead of after full synthesis.
response = client.audio.speech.create(
model="tts-voice",
voice="ananya",
input="नमस्ते!",
response_format="pcm", # raw signed 16-bit PCM
# response_format="mulaw" for an 8 kHz telephony (PSTN) leg
)
# response.iter_bytes() yields audio frames as they are produced
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.