Use a WebSocket-controlled interface to obtain temporary credentials and establish an AOQ media connection.
Use the control WebSocket to establish the session and obtain temporary credentials. Once AOQ is connected, use it to send and receive audio. Keep the control WebSocket open throughout the session.
Download the AOQ Client SDK for your platform from SDK Downloads. For macOS, download the SDK and Opus plugin for v1.4.0.
Establish a WebSocket Connection
Establish the WebSocket connection using the endpoint and authentication instructions in WebSocket access. Add the following configuration to the session object in session.update.
{"transport":{"type":"aoq","aoq":{"ws_audio":false}}}
Establish the AOQ Media Connection
- Wait for
session.updated. The AOQ connection information resides in the returnedsessionobject—read it undertransport.aoq. Temporary credentials must be reacquired for each new session. Do not log them. - Pass the
sid,aoqTokenForClient,clientRelayCertFingerprint, andclientRelayEndpointsvalues returned for the same session to the AOQ Client SDK. Also passworkspaceIdHashfromextraInfoto the SDK. Each Relay address containsendpoint,port, androute_index. - Use the returned
sidand temporary credentials to initiate the AOQ connection within 5 minutes of receivingsession.updated. After receiving the connection-success callback, start audio capture and transmission, and play downstream audio via the SDK. Maintain the WebSocket connection throughout the session. - At session end, stop audio capture and playback, disconnect AOQ, then close the WebSocket session.
When troubleshooting audio transmission issues, retrieve the AOQ session ID from session.updated’s session.transport.aoq.sid. session.id identifies the application session.
Receive server events
Once the media connection is ready, receive server events over the control WebSocket or the AOQ data track. To receive events over AOQ, subscribe to the data track and handle the SDK data message callback. The macOS SDK uses onDataMsg:. If both paths deliver an event with the same event_id, process it once.
Audio Transmission
Upload upstream speech via AOQ. If you send session.input_audio.append over WebSocket, the service returns audio_requires_aoq_media.
The ws_audio field in the aoq object defaults to false. When set to true, the service also sends downstream audio over WebSocket. For business integration details, see Task Delegation and Tools. For session and task events, refer to Client events and Server events.