Skip to main content
Let the character answer using the user’s message, spoken instructions, and conversation history. First connect the player. Control events use window.player.ws from the player examples. Choose the microphone code for your TRTC or Agora player.

1. Send text and request an answer

Use a new item.id for each message. Wait for conversation.item.created with item.id equal to user_1, then send:
Send these events with window.player.ws.send(JSON.stringify(event)) after the WebSocket connects. Waiting for the item acknowledgement ensures the reply includes the new message.

2. Display the reply

Accumulate delta by response_id and reconcile it with the full text in response.output_text.done. Complete the UI using the actual response.done status, including failures and cancellations. Finished text does not mean finished audio.

3. Enable the microphone

This is ordinary voice conversation: the character recognizes speech and generates an answer. Do not enable A2A passthrough for this. Choose the code for your player rather than adding both versions. Add these buttons to index.html:

TRTC

Add this to the TRTC player’s main.js:

Agora

Add this to the Agora player’s main.js, where AgoraRTC is already imported:
Turning the microphone off also cancels pending permission or publication work and closes its track when it resolves. In the Agora player’s existing Stop handler, call await stopMicrophone() before leaving the channel. Rebuild main.js and refresh the page for either version. Use HTTPS or localhost and request microphone permission from a button click. Default turn detection starts replies automatically; do not send another response.create for the same turn. Keep text input available if permission is denied.

4. Interrupt or play next

This cancels the active response and clears pending work. It returns an error when no response is active. Terminal events can still arrive after cancellation; use their actual status to update the UI.
New requests default to interrupt, which interrupts current output and clears pending work. after_current_response waits for the current response; at most one request may be pending. reject_if_busy returns an error while busy and can help prevent repeated button actions. A pending request keeps the input and configuration captured when submitted; later image or configuration changes do not rewrite it.