October 7, 2024
OpenAI Realtime client in 75 lines of Python
I've been hacking on an OpenAI Realtime API service for @pipecat_ai and it occurred to me that the core voice-to-voice loop in pseudo-code is quite small. (Which is a nice testament to the API design!)
And, of course, one thing led to another. It turns out actual working Python code is ~75 lines.
So ... here's a command-line client for `gpt-4o-realtime-preview-2024-10-01`.
https://t.co/yBpPzZljyp
No error handling. No configurability. No echo cancellation, so you'll need to wear headphones.
But it works.
Download the gist.
`pip install asyncio pyaudio websockets`
python https://t.co/qLvNkBSgaC
That 75-line Python script is a standalone little program.
There's also a @pipecat_ai branch with a (nearly) complete implementation of the OpenAI Realtime API with hooks for conversation storage and function calling, echo cancellation, noise reduction, compatibility with client libraries for Web, Android, iOS, C++, etc ...
https://t.co/SpteImJ7ue