1234567891011121314151617181920212223242526272829 |
- 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())
|