Generates audio from the input text using text-to-speech models.
Method
client . audio . speech . create ( params )
Request Parameters
The text to generate audio for. The maximum length is 4096 characters.
One of the available TTS models: openai/tts-1, openai/tts-1-hd, or openai/gpt-4o-mini-tts.
The voice to use when generating the audio. Supported voices are:
alloy
ash
ballad
coral
echo
fable
onyx
nova
sage
shimmer
verse
Previews of the voices are available in the Text to speech guide .
Control the voice of your generated audio with additional instructions. Does not work with tts-1 or tts-1-hd.
The format to audio in. Supported formats are mp3, opus, aac, flac, wav, and pcm. Default: mp3
The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default. Default: 1.0
The format to stream the audio in. Supported formats are sse and audio. sse is not supported for tts-1 or tts-1-hd.
Response
Returns streaming audio data as a binary Response object that can be saved to a file or streamed directly to users.
Example
Basic Usage
With Options
Streaming
const mp3 = await client . audio . speech . create ({
model: "openai/tts-1" ,
voice: "alloy" ,
input: "The quick brown fox jumped over the lazy dog." ,
});
const buffer = Buffer . from ( await mp3 . arrayBuffer ());
await fs . promises . writeFile ( "speech.mp3" , buffer );