mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Add audio example usage
This commit is contained in:
parent
c97ba0c88e
commit
705ad02954
5 changed files with 46 additions and 5 deletions
28
etc/examples/audio.py
Normal file
28
etc/examples/audio.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import asyncio
|
||||
from g4f.client import AsyncClient
|
||||
import g4f.Provider
|
||||
import g4f.models
|
||||
|
||||
async def main():
|
||||
client = AsyncClient(provider=g4f.Provider.PollinationsAI)
|
||||
|
||||
# Generate audio with PollinationsAI
|
||||
response = await client.chat.completions.create(
|
||||
model="openai-audio",
|
||||
messages=[{"role": "user", "content": "Say good day to the world"}],
|
||||
audio={ "voice": "alloy", "format": "mp3" },
|
||||
)
|
||||
response.choices[0].message.save("alloy.mp3")
|
||||
|
||||
# Transcribe a audio file
|
||||
with open("audio.wav", "rb") as audio_file:
|
||||
response = await client.chat.completions.create(
|
||||
messages="Transcribe this audio",
|
||||
provider=g4f.Provider.Microsoft_Phi_4,
|
||||
media=[[audio_file, "audio.wav"]],
|
||||
modalities=["text"],
|
||||
)
|
||||
print(response.choices[0].message.content)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue