Audio (TTS, STT, Translation)
Text-to-speech, speech-to-text, and audio translation across OpenAI, ElevenLabs, Deepgram, and Cartesia.
Overview
The Audio API exposes three operations behind a unified, OpenAI-compatible surface:
- Text-to-Speech (
/v1/audio/speech) -- synthesize speech from text - Speech-to-Text (
/v1/audio/transcriptions) -- transcribe audio in its source language - Translation (
/v1/audio/translations) -- transcribe audio and translate to English
You can route the same operation to different providers (OpenAI Whisper, Deepgram Nova-3, ElevenLabs, Cartesia Sonic, Google Cloud Speech) by changing the model identifier. Cost, latency, and language support vary; pick per use case.
Text-to-Speech
POST https://api.allroutes.ai/v1/audio/speech
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | TTS model (e.g., tts-1, tts-1-hd, eleven_turbo_v2_5, cartesia-sonic) |
input | string | Yes | Text to synthesize (max 4096 characters) |
voice | string | Yes | Voice identifier (depends on model) |
response_format | string | No | mp3 (default), opus, aac, flac, wav, pcm |
speed | float | No | Playback speed 0.25-4.0 (default: 1.0) |
Example
curl https://api.allroutes.ai/v1/audio/speech \
-H "Authorization: Bearer allroutes_sk_..." \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Hello, world. This is a test of text-to-speech.",
"voice": "alloy",
"response_format": "mp3"
}' \
--output speech.mp3
The response body is the raw audio bytes. The Content-Type header reflects the requested format.
Voice IDs
| Model | Available Voices |
|---|---|
tts-1 / tts-1-hd | alloy, echo, fable, onyx, nova, shimmer |
eleven_turbo_v2_5 | Any ElevenLabs voice ID |
cartesia-sonic | Any Cartesia voice ID |
google-tts | en-US-Wavenet-A ... en-US-Wavenet-J, etc. |
Speech-to-Text
POST https://api.allroutes.ai/v1/audio/transcriptions
Request Body (multipart/form-data)
| Field | Type | Required | Description |
|---|---|---|---|
file | file | Yes | Audio file (mp3, mp4, mpeg, mpga, m4a, wav, webm; max 25 MB) |
model | string | Yes | STT model (e.g., whisper-1, deepgram-nova-3, groq-whisper-large-v3) |
language | string | No | ISO-639-1 hint (e.g., en, es, de); auto-detected when omitted |
prompt | string | No | Style hint or domain vocabulary |
response_format | string | No | json (default), text, srt, vtt, verbose_json |
temperature | float | No | 0.0-1.0 (default: 0.0) |
timestamp_granularities | array | No | ["word"], ["segment"], or both (verbose_json only) |
Example
curl https://api.allroutes.ai/v1/audio/transcriptions \
-H "Authorization: Bearer allroutes_sk_..." \
-F [email protected] \
-F model=whisper-1 \
-F response_format=verbose_json \
-F "timestamp_granularities[]=segment"
Response (verbose_json)
{
"task": "transcribe",
"language": "english",
"duration": 412.5,
"text": "Welcome everyone. Today we'll cover...",
"segments": [
{"id": 0, "start": 0.0, "end": 4.2, "text": "Welcome everyone."},
{"id": 1, "start": 4.2, "end": 8.1, "text": "Today we'll cover..."}
]
}
Translation
POST https://api.allroutes.ai/v1/audio/translations
Same request shape as transcription, but the model translates source-language audio into English text. Currently only whisper-1 and groq-whisper-large-v3 support translation.
curl https://api.allroutes.ai/v1/audio/translations \
-H "Authorization: Bearer allroutes_sk_..." \
-F file=@german_lecture.mp3 \
-F model=whisper-1
SDK Examples
Python
# TTS
audio_bytes = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="Hello, world.",
)
with open("speech.mp3", "wb") as f:
f.write(audio_bytes)
# STT
with open("meeting.mp3", "rb") as f:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=f,
response_format="verbose_json",
)
print(transcript.text)
Node.js
import fs from "fs";
// TTS
const audio = await client.audio.speech.create({
model: "tts-1",
voice: "alloy",
input: "Hello, world.",
});
fs.writeFileSync("speech.mp3", Buffer.from(await audio.arrayBuffer()));
// STT
const transcript = await client.audio.transcriptions.create({
model: "whisper-1",
file: fs.createReadStream("meeting.mp3"),
response_format: "verbose_json",
});
console.log(transcript.text);
Supported Models
| Model | Operation | Strength |
|---|---|---|
tts-1 | TTS | Cheap, fast, 6 voices |
tts-1-hd | TTS | Higher fidelity, slower |
eleven_turbo_v2_5 | TTS | Best voice cloning, lowest latency |
cartesia-sonic | TTS | Sub-100ms first-byte latency |
whisper-1 | STT | 99 languages, broad support |
deepgram-nova-3 | STT | Best English accuracy, low latency |
groq-whisper-large-v3 | STT | 5-10x faster than OpenAI Whisper |
assembly-best | STT | Speaker diarization, sentiment |
Streaming TTS
For low-latency voice applications, set stream: true to receive audio chunks as they're generated:
curl https://api.allroutes.ai/v1/audio/speech \
-H "Authorization: Bearer allroutes_sk_..." \
-H "Content-Type: application/json" \
-d '{"model":"cartesia-sonic","voice":"...","input":"Hello","stream":true}' \
--output - | mpv -
The chunked response is raw audio in the requested response_format. See Realtime API for full bidirectional voice agent flows.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
400: file too large | Audio over 25 MB | Compress to MP3 64kbps or split |
| Garbled transcription | Wrong language hint | Drop language to auto-detect or fix the hint |
| TTS sounds robotic | Using tts-1 for production | Switch to tts-1-hd, eleven_turbo_v2_5, or cartesia-sonic |
| Long queue times | Provider rate-limit | Add provider.order fallback or use BYOK |
See Also
- Realtime API -- WebSocket-based bidirectional voice agents
- Files API -- alternative way to upload large audio
- Models API -- list audio models with current pricing
- Cost Optimization -- pick the right STT/TTS model for your latency budget