Output formats
Choose the encoding, container and sample rate of Bakbak TTS audio with output_format
Both TTS endpoints take an output_format object that sets exactly what audio you receive: the encoding, the container and the sample rate. Send it on every request.
If you leave it out, /v1/text-to-speech returns a WAV file and the streaming endpoint sends 32-bit float PCM, both at 24 kHz.
Fields
The streaming endpoint always sends raw audio chunks, so wav and mp3 are only available on /v1/text-to-speech.
Encodings
All audio is mono.
pcm_s16le is half the size of pcm_f32le, and the G.711 encodings are a quarter of the size, so choosing the encoding your player needs also reduces the bandwidth of each chunk.
Common choices
Streaming example
Ask for 8 kHz μ-law on the stream:
The events have the same shape as always. The only difference is that the base64 data in each chunk event now holds μ-law bytes instead of 32-bit floats.
This Python example streams 16-bit PCM and saves it as a WAV file:
In a real-time app, play or forward each decoded chunk as it arrives instead of collecting them.
Non-streaming examples
A wav container can hold any of the four encodings. For pcm_s16le the file has a standard 44-byte header. For pcm_f32le, pcm_mulaw and pcm_alaw it has the extended header that WAVE requires for those formats (58 bytes, with a fact chunk). Tools such as FFmpeg, SoX and libsndfile read both. Python’s built-in wave module reads only the 16-bit form.
With the standard model, WAV responses are streamed as they are generated, so the size fields in the WAV header are set to 0xFFFFFFFF rather than the real length. Read the body to the end instead of relying on those fields.
Response headers
When you send output_format, the response includes headers that describe the audio you receive:
An MP3 file states its own sample rate in its frames. Responses to requests without output_format don’t include these headers.
On /v1/text-to-speech, Content-Type and the download filename follow the container you chose:
Validation errors
An invalid output_format is rejected with 422 Unprocessable Entity before any audio is generated, so it is not billed. The loc field points to the field at fault:
These requests are rejected:
All problems in a request are reported together, one entry each in detail.

