import base64
speech_file_path = "./sounds/chat_completions_tts.mp3"
completion = client.chat.completions.create(
model="gpt-4o-audio-preview",
modalities=["text", "audio"],
audio={"voice": "alloy", "format": "mp3"},
messages=[
{
"role": "system",
"content": "You are a helpful assistant that can generate audio from text. Speak in a British accent and enunciate like you're talking to a child.",
},
{
"role": "user",
"content": tts_text,
}
],
)
mp3_bytes = base64.b64decode(completion.choices[0].message.audio.data)
with open(speech_file_path, "wb") as f:
f.write(mp3_bytes)
speech_file_path = "./sounds/chat_completions_tts_fast.mp3"
completion = client.chat.completions.create(
model="gpt-4o-audio-preview",
modalities=["text", "audio"],
audio={"voice": "alloy", "format": "mp3"},
messages=[
{
"role": "system",
"content": "You are a helpful assistant that can generate audio from text. Speak in a British accent and speak really fast.",
},
{
"role": "user",
"content": tts_text,
}
],
)
mp3_bytes = base64.b64decode(completion.choices[0].message.audio.data)
with open(speech_file_path, "wb") as f:
f.write(mp3_bytes)