WebSocketAudioAdapter

WebSocketAudioAdapter(
    websocket: WebSocket,
    *,
    logger: Logger | None = None
)
Observer for the OpenAI Realtime API.
Observer for handling function calls from the OpenAI Realtime API.
Parameters:
NameDescription
websocketType: WebSocket
loggerType: logging.Logger | None

Default: None

Instance Methods

handle_speech_started_event

handle_speech_started_event(self) -> None
Handle interruption when the caller’s speech starts.

initialize_session

initialize_session(self) -> None
Control initial session with OpenAI.

on_close

on_close(self) -> None
Handle close of RealtimeClient.

on_event

on_event(self, event: RealtimeEvent) -> None
Receive events from the OpenAI Realtime API, send audio back to websocket. Parameters:
NameDescription
eventType: RealtimeEvent

run

run(self, agent: RealtimeAgent) -> 
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:
NameDescription
agentThe realtime agent attached to the observer.

Type: RealtimeAgent

run_loop

run_loop(self) -> None
Reads data from websocket and sends it to the RealtimeClient.

send_mark

send_mark(self) -> None

wait_for_ready

wait_for_ready(self) -> None
Get the event that is set when the observer is ready.