Audio

Synthesize speech from text

Generates speech from text using OpenAI or ElevenLabs. When the requested provider has no usable key (or the provider rejects it), another configured provider stands in and the substitution is reported via provider/fallbackFrom and the X-B4M-Tts-Provider* headers. Input length is capped per provider (OpenAI 4096 characters, ElevenLabs 10000), and an output format the chosen provider cannot produce is rejected with a 422 before any provider cost is incurred. The default encoding: "binary" returns the raw audio bytes; encoding: "base64" returns JSON. Audio over the ~4MB response ceiling is returned by signed URL (a 303 for binary, the delivery: "url" variant for base64). Generated audio is saved to the file browser unless the call sets preview; the outcome is reported in the JSON save fields and the X-B4M-Audio-* headers - fetch the saved copy from fileUrl / X-B4M-Audio-File-Url, since GET /api/files/{id} fails closed until moderation completes. Authenticate with an API key (b4m_live_) or a JWT.

post/api/ai/tts

Request

  • Base URL: https://your-deployment.example.com
  • URL: https://your-deployment.example.com/api/ai/tts
  • Auth: one of:
    • HTTP bearer
    • API key in header x-api-key

Request body

textstring required
provider'openai' | 'elevenlabs'
modelstring
voicestring
format'mp3' | 'wav' | 'opus' | 'aac' | 'flac' | 'pcm'
stabilitynumber
similarityBoostnumber
languageCodestring
encoding'binary' | 'base64'
previewboolean

Example request

{
  "text": "Your password has been reset.",
  "provider": "openai",
  "voice": "alloy",
  "format": "mp3"
}

Response

Speech synthesized. Binary bodies carry a Content-Type that follows the requested format (audio/mpeg for mp3, else audio/wav, audio/opus, audio/aac, audio/flac, audio/pcm). The default encoding: "binary" returns the raw audio bytes; encoding: "base64" returns the JSON body. Audio over the ~4MB response ceiling cannot ride in the body: the binary encoding answers 303 instead, and the base64 encoding returns the delivery: "url" variant, whose url is a time-limited signed GET for the audio (bytes is its size).

OR

Changes

No recorded changes to this operation across all 1 revision of this API.