> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.agentchat.realtime.experimental.WebSocketAudioAdapter

<h2 id="autogen.agentchat.realtime.experimental.WebSocketAudioAdapter" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">WebSocketAudioAdapter</span>
</h2>

```python theme={null}
WebSocketAudioAdapter(
    websocket: WebSocket,
    *,
    logger: Logger | None = None
)
```

Observer for the OpenAI Realtime API.<br />Observer for handling function calls from the OpenAI Realtime API.<br />

<b>Parameters:</b>

| Name        | Description                                                   |
| ----------- | ------------------------------------------------------------- |
| `websocket` | **Type:** WebSocket                                           |
| `logger`    | **Type:** logging.Logger \| None<br /><br />**Default:** None |

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### handle\_speech\_started\_event

```python theme={null}
handle_speech_started_event(self) -> None
```

Handle interruption when the caller's speech starts.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### initialize\_session

```python theme={null}
initialize_session(self) -> None
```

Control initial session with OpenAI.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### on\_close

```python theme={null}
on_close(self) -> None
```

Handle close of RealtimeClient.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### on\_event

```python theme={null}
on_event(self, event: RealtimeEvent) -> None
```

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

<b>Parameters:</b>

| Name    | Description                                                                                                          |
| ------- | -------------------------------------------------------------------------------------------------------------------- |
| `event` | **Type:** [RealtimeEvent](/docs/api-reference/autogen/agentchat/realtime/experimental/realtime_events/RealtimeEvent) |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### run

```python theme={null}
run(self, agent: RealtimeAgent) -> 
```

Run the observer with the agent.<br />When implementing, be sure to call `self._ready_event.set()` when the observer is ready to process events.<br />

<b>Parameters:</b>

| Name    | Description                                                                     |
| ------- | ------------------------------------------------------------------------------- |
| `agent` | The realtime agent attached to the observer.<br /><br />**Type:** RealtimeAgent |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### run\_loop

```python theme={null}
run_loop(self) -> None
```

Reads data from websocket and sends it to the RealtimeClient.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### send\_mark

```python theme={null}
send_mark(self) -> None
```

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### wait\_for\_ready

```python theme={null}
wait_for_ready(self) -> None
```

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

<br />
