Official documentation: https://platform.openai.com/docs/guides/text-to-speech
Generates audio from the input text.
Request Parameters
One of the available TTS models: tts-1, tts-1-hd, gpt-4o-mini-tts.
The text to generate audio for. The maximum length is 4096 characters.
The voice to use when generating the audio. Supported voices are: alloy, echo, fable, onyx, nova, shimmer.
The format of the audio. Supported formats are: mp3, opus, aac, flac.
The speed of the generated audio. Select a value from 0.25 to 4.0.
Response
Returns the audio file content in the specified format.
curl -X POST https://api.example.com/v1/audio/speech \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "The quick brown fox jumped over the lazy dog.",
"voice": "alloy"
}' \
--output speech.mp3
Binary audio file content