Skip to content

Instantly share code, notes, and snippets.

@morganmcg1
Created October 23, 2024 10:07
Show Gist options
  • Save morganmcg1/57175f37fed13de7c7a0a8438444401c to your computer and use it in GitHub Desktop.
Save morganmcg1/57175f37fed13de7c7a0a8438444401c to your computer and use it in GitHub Desktop.
import base64
from openai import OpenAI
import weave
import wave
client = OpenAI()
weave.init("audio-in-weave")
@weave.op()
def make_audio_file():
completion = client.chat.completions.create(
model="gpt-4o-audio-preview",
modalities=["text", "audio"],
audio={"voice": "alloy", "format": "wav"},
messages=[
{
"role": "user",
"content": "Is a golden retriever a good family dog?"
}
]
)
print(completion.choices[0])
wav_bytes = base64.b64decode(completion.choices[0].message.audio.data)
with open("dog.wav", "wb") as f:
f.write(wav_bytes)
return wave.open("dog.wav", "rb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment