TwilioAudioAdapter

class TwilioAudioAdapter(RealtimeObserver)

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

__init__

def __init__(websocket: "WebSocket", *, logger: Optional[Logger] = None)

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

Arguments:

  • websocket - WebSocket the websocket connection to the Twilio service

on_event

async def on_event(event: dict[str, Any]) -> None

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

handle_speech_started_event

async def handle_speech_started_event() -> None

Handle interruption when the caller’s speech starts.

send_mark

async def send_mark() -> None

Send a mark of audio interruption to the Twilio websocket.

run_loop

async def run_loop() -> None

Run the adapter loop.

initialize_session

async def initialize_session() -> None

Control initial session with OpenAI.