Created
October 23, 2024 10:07
-
-
Save morganmcg1/57175f37fed13de7c7a0a8438444401c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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