Create speech
audio.speech.create(SpeechCreateParams**kwargs ) -> BinaryResponseContent
POST
/audio/speechGenerates audio from the input text.
Returns the audio file content, or a stream of audio events.
The tts-1, tts-1-hd, gpt-4o-mini-tts, gpt-4o-mini-tts-2025-03-20, and
gpt-4o-mini-tts-2025-12-15 models are deprecated and scheduled to shut down
on January 6, 2027. These examples use the existing Speech API; for new
integrations, migrate to gpt-realtime-2.1-mini through the
Realtime API. See the
deprecation schedule for migration details.
Create speech
from pathlib import Path
import openai
speech_file_path = Path(__file__).parent / "speech.mp3"
with openai.audio.speech.with_streaming_response.create(
model="gpt-4o-mini-tts",
voice="alloy",
input="The quick brown fox jumped over the lazy dog."
) as response:
response.stream_to_file(speech_file_path)