Audio formats¶
All output is mono at 24 000 Hz (sample_rate must be 24000 if given). The format field picks the container:
format |
Content-Type | What you get | Use it for |
|---|---|---|---|
wav (default) |
audio/wav |
RIFF/WAVE, 16-bit PCM | files, quick tests, players |
pcm16 |
audio/L16; rate=24000 style raw |
signed 16-bit little-endian samples, no header | your own decoder/mixer, telephony bridges, browsers via Web Audio |
opus |
audio/ogg; codecs=opus |
Ogg/Opus, 48 kbit/s, 20 ms packets, one Ogg page per packet | web playback, storage, WebRTC-adjacent pipelines |
Streaming vs buffered¶
POST /v1/tts streams by default ("stream": true): chunked transfer, the first bytes after the first decoded 80 ms frame.
- WAV while streaming carries a placeholder length in its header. Most players and
ffmpeghandle it; strict parsers may not. Send"stream": falseto receive a complete file with a correct length (andContent-Length). - Opus while streaming is a valid, growing Ogg stream; with
"stream": falseyou get a complete, seekable file. - pcm16 has no header either way.
On the WebSocket there is no container for a message stream, so format: wav is downgraded to pcm16 (the start event tells you
which format is in effect); opus sends Ogg pages as binary messages.
Converting¶
# WAV → MP3 / M4A
ffmpeg -i out.wav -c:a libmp3lame -q:a 3 out.mp3
ffmpeg -i out.wav -c:a aac -b:a 96k out.m4a
# raw PCM → 8 kHz μ-law for telephony
ffmpeg -f s16le -ar 24000 -ac 1 -i out.pcm -ar 8000 -acodec pcm_mulaw out.ul
Frame timing¶
The engine produces audio in 80 ms frames (1 920 samples). The first frame is decoded alone, then frames are decoded four at a time, so after the first chunk audio arrives in ~320 ms steps that are each ahead of real time (real-time factor ≈ 0.14–0.19). Buffer ~100–200 ms before starting playback for jitter-free output over the public internet; see the streaming guide.