# Audio Speech API — Text to speech Source: https://ofox.ai/docs/api/openai/audio-speech Turns text into speech. Compatible with OpenAI's `POST /v1/audio/speech`; the response body is the audio file itself (binary), not JSON. | Family | Model | Notes | |---|---|---| | ElevenLabs | `elevenlabs/eleven_v4` | See [ElevenLabs](https://ofox.ai/docs/develop/models/elevenlabs) | | Gemini TTS | `google/gemini-3.8-flash-tts` and others | See [Gemini TTS](https://ofox.ai/docs/develop/models/gemini-tts) | Accepted values for `voice`, `response_format` and other parameters vary by model; the family pages are authoritative. ## Quickstart - base_url: `https://api.ofox.ai/v1` - Endpoint: `https://api.ofox.ai/v1/audio/speech` - Model ID: `google/gemini-3.8-flash-tts` **Python** ```python filename="speech.py" import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.ai/v1", api_key=os.environ["OFOX_API_KEY"]) with client.audio.speech.with_streaming_response.create( model="google/gemini-3.8-flash-tts", voice="Kore", input="Hello, and welcome to OfoxAI text to speech.", response_format="wav", ) as resp: resp.stream_to_file("speech.wav") ``` **cURL** ```bash filename="Terminal" curl https://api.ofox.ai/v1/audio/speech \ -H "Authorization: Bearer $OFOX_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "google/gemini-3.8-flash-tts", "voice": "Kore", "input": "Hello, and welcome to OfoxAI text to speech.", "response_format": "wav" }' \ --output speech.wav ``` ## Request parameters **model** `string` · required Model ID; see the table above. **input** `string` · required The text to synthesize. An empty value returns 400. **voice** `string` The voice. Required for Gemini TTS, where it takes a Google voice name (e.g. `Kore`); for ElevenLabs it takes a voice ID (e.g. `21m00Tcm4TlvDq8ikWAM`). OpenAI voice names (e.g. `alloy`) do not work with either family. **response_format** `string` Audio format. Accepted values vary by model: Gemini TTS supports `wav` and `pcm`; ElevenLabs supports `mp3`, `opus`, `wav` and `pcm`. An unsupported format returns 400. **instructions** `string` Tone and style instructions, such as "read this in a cheerful tone". Applies to Gemini TTS. **language_code** `string` Language code, such as `cmn-CN` (Gemini TTS) or `zh` (ElevenLabs). If omitted, the model infers the language from the text. **stream_format** `string` · values `sse` With `sse`, audio chunks are streamed as Server-Sent Events. Applies to Gemini TTS. **provider_options** `object` Provider-specific parameters, passed through to the provider, e.g. ElevenLabs' `{"elevenlabs": {"voice_settings": {...}}}`. See each family page. ## Response On success, HTTP 200 with the audio file as the response body; `Content-Type` matches the format: | response_format | Content-Type | |---|---| | `mp3` | `audio/mpeg` | | `wav` | `audio/wav` | | `opus` | `audio/ogg` | | `pcm` | `audio/L16;rate=;channels=1`, headerless 16-bit PCM | Write the response body straight to a file. Errors are returned as JSON with `Content-Type` `application/json`, so check the status code first to avoid saving an error message as an audio file. ## Common errors | HTTP | Error message | Cause | Fix | |---|---|---|---| | 400 | `model and input are required.` | `model` is missing, or `input` is empty | Supply the missing parameters | | 400 | `voice is required for speech completion` | `voice` not sent for Gemini TTS | Pass a voice name, such as `Kore` | | 400 | `unsupported Gemini response_format: mp3` | The model does not support the chosen format | Use a format listed on the family page | | 400 | `Request contains an invalid argument.` | The Gemini TTS voice name does not exist | Use a valid voice name | | 404 | `A voice with voice_id 'alloy' was not found.` | The ElevenLabs voice ID does not exist | Use a valid voice ID | | 400 `endpoint_not_supported` | `Model 'openai/gpt-5.4' does not support the /v1/audio/speech endpoint on this platform.` | The chosen model is not a speech synthesis model | Use a model from the table above | For the full list of error codes, see [Error handling](https://ofox.ai/docs/develop/guides/error-handling).