Create speech
audio.speech.create(SpeechCreateParams**kwargs) -> BinaryResponseContent
POST/audio/speech
Generates audio from the input text.
Returns the audio file content, or a stream of audio events.
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)