Docs/REST API

REST · text-to-speech.

A single endpoint that takes a sentence and returns audio. Use it for batch jobs, non-realtime workloads, and any system that already speaks HTTP.

Endpoint

POSThttps://api.leanvoice.ai/v1/audio/speech

Returns the audio as the response body. Default response is a WAV file; pass format to switch.

Request body

inputstringRequired
Text to synthesise. Up to 4 000 characters per request. Expression tags are accepted inline.
voicestringRequired
One of the ten voice ids from the voice library. Defaults to meera if omitted.
languagestringOptional
ISO 639-1 language code. Auto-detected from the input if omitted.
formatstringOptional
One of wav, mp3, opus, pcm_s16le_24k, pcm_s16le_16k, mulaw_8k. Default wav.
stepsintegerOptional
Synthesis quality. 4 (draft, fastest), 8 (balanced, default), 10 (studio).
speedfloatOptional
Speaking rate. 0.5 to 2.0, default 1.0.
modelstringOptional
Model identifier. Currently aayush-tts-1 (default); pinned for backwards compatibility.

Response

Audio bytes in the requested format. The following headers carry per-request telemetry:

HeaderMeaning
X-Audio-DurationLength of synthesised audio in seconds, to three decimals.
X-Request-IdOpaque request id, include in support tickets.
X-Characters-BilledCharacters that counted toward your monthly quota.

Examples

curl
curl https://api.leanvoice.ai/v1/audio/speech \
  -H "Authorization: Bearer $LEANVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"voice":"arjun","input":"Welcome to channel seventeen.","format":"mp3"}' \
  --output greeting.mp3
python
from leanvoice import LeanVoice
client = LeanVoice(api_key=os.environ["LEANVOICE_API_KEY"])
audio = client.speech.create(voice="arjun", input="Welcome.", format="mp3")
open("out.mp3","wb").write(audio.bytes)
node
const audio = await client.speech.create({ voice:"arjun", input:"Welcome.", format:"mp3" });
await writeFile("out.mp3", Buffer.from(await audio.arrayBuffer()));

OpenAI compatibility

The endpoint accepts OpenAI's exact audio/speech request shape, so any client built for OpenAI can switch by changing one URL. Use the openai SDK with base_url set to https://api.leanvoice.ai/v1:

python
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["LEANVOICE_API_KEY"],
    base_url="https://api.leanvoice.ai/v1",
)

audio = client.audio.speech.create(
    model="aayush-tts-1",
    voice="meera",
    input="Same SDK, new base URL.",
)
audio.stream_to_file("out.wav")

The mapping is one-to-one: voice names match the OpenAI shape where compatible (alloy aliases to meera, onyx to arjun, etc.) and our extended fields (steps, speed) ride along as additional parameters that OpenAI's SDK passes through unchanged.