Skip to main content
POST
/
v1
/
audio
/
speech
Create Speech
curl --request POST \
  --url https://api.example.com/v1/audio/speech \
  --header 'Content-Type: application/json' \
  --data '
{
  "input": "<string>",
  "model": "<string>",
  "voice": "<string>",
  "instructions": "<string>",
  "response_format": "<string>",
  "speed": 123,
  "stream_format": "<string>"
}
'
Generates audio from the input text using text-to-speech models.

Method

client.audio.speech.create(params)

Request Parameters

input
string
required
The text to generate audio for. The maximum length is 4096 characters.
model
string
required
One of the available TTS models: openai/tts-1, openai/tts-1-hd, or openai/gpt-4o-mini-tts.
voice
string
required
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.
instructions
string
Control the voice of your generated audio with additional instructions. Does not work with tts-1 or tts-1-hd.
response_format
string
The format to audio in. Supported formats are mp3, opus, aac, flac, wav, and pcm.Default: mp3
speed
number
The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default.Default: 1.0
stream_format
string
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

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);

Build docs developers (and LLMs) love