Skip to main content

TwilioAudioAdapter

Adapter for streaming audio from Twilio to OpenAI Realtime API and vice versa.
Adapter for streaming audio from Twilio to OpenAI Realtime API and vice versa.
Parameters:

Instance Methods

handle_speech_started_event

Handle interruption when the caller’s speech starts.

initialize_session

Control initial session with OpenAI.

on_close

Handle close of RealtimeClient.

on_event

Receive events from the OpenAI Realtime API, send audio back to Twilio. Parameters:

run

Run the observer with the agent.
When implementing, be sure to call self._ready_event.set() when the observer is ready to process events.
Parameters:

run_loop

Run the adapter loop.

send_mark

Send a mark of audio interruption to the Twilio websocket.

wait_for_ready

Get the event that is set when the observer is ready.