TwilioAudioAdapter

class TwilioAudioAdapter(RealtimeObserver)

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

__init__

def __init__(websocket: "WebSocket")

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

Arguments:

  • websocket - WebSocket the websocket connection to the Twilio service

update

async def update(response: 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

async def run() -> None

Run the adapter.

Start reading messages from the Twilio websocket and send audio to OpenAI.

initialize_session

async def initialize_session() -> None

Control initial session with OpenAI.