Text-to-Speech
Text-to-Speech
Handling raw audio responses, voice/model matching, formats, and streaming frame protocols.
TTS runs over POST /v1/audio/speech (REST) and
WS /v1/audio/speech/stream/{voice_id} (streaming). See
Text-to-Speech for the full reference.
The response won’t parse as JSON
POST /v1/audio/speech returns raw audio bytes, not JSON. The
Content-Type matches the requested format (e.g. audio/mpeg, audio/wav).
Write the body straight to a file — don’t call .json() on it.
Voice errors / wrong or missing voice
voiceis required for ElevenLabs models and must be a valid ID for that model’s brand.- A voice from one brand won’t work with a model from another. Browse valid IDs with
GET /v1/audio/voicesand filter bybrandormodelso you only pick voices usable with the model you call. - Sarvam models use
speaker(defaultanushka), notvoice.
response_format rejected
Not every format is valid in every mode. wav_* formats are non-streaming
only — request them with stream: false. Streaming supports mp3_*,
pcm_*, ulaw_8000, alaw_8000, and opus_*.
WebSocket streaming produces no audio
The frame protocol depends on the model family:
- Standard models (Kokoro, Cartesia, …) — send
input_text_buffer.appendtheninput_text_buffer.commit; audio arrives asconversation.item.audio_output.delta(base64). - ElevenLabs models — the first frame must be
initializeConnection({ "text": " " }), thensendText, thencloseConnection({ "text": "" }); audio arrives asAudioOutput(base64).
Audio deltas are base64 — decode before playing or writing.
Still stuck?
See the Mesh API error reference or email contact@meshapi.ai.