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)

ParameterTypeDescription
modelrequiredstringTTS model ID. Call GET /v1/models and pick a model with type TTS.
inputrequiredstringText to synthesize. The maximum length varies by model; see GET /v1/models.
voicerequiredstringVoice name. See the Voices section below for available options.
response_formatstringAudio format: "mp3" (default), "wav", "opus", "flac", "aac", "pcm" (raw S16LE), "mulaw" (G.711 8kHz, for telephony).
stream_formatstringSet to "sse" to stream audio as OpenAI speech events (speech.audio.delta / speech.audio.done). See Streaming below.
sample_rateintegerOutput 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 — always read that list rather than assuming a naming scheme, since it differs by model: some models use short names (ananya), others use a longer name_language_style form (ritu_hi_banking) across 200+ persona voices. Common voices on the default model:

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:

bash
# 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):

stream_tts.py
# 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

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

400
missing_input / voice_not_supported / language_not_supported
Missing required field, or a voice/language this model doesn’t offer — see the voice and language lists above.
401
invalid_api_key
Missing or invalid API key.
402
insufficient_credit
Wallet is empty. Top up credits before retrying.
403
kyc_required
KYC verification is required before this call.
404
model_not_found
The model ID does not exist or is not available to your account.
503
model_unavailable
Every configured route for this model failed. Retry after a short wait.