window.player.ws from the player examples. Choose the microphone code for your TRTC or Agora player.
1. Send text and request an answer
item.id for each message. Wait for conversation.item.created with item.id equal to user_1, then send:
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
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: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
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.