Use WebSocket to establish a session, transmit audio, and handle task events.
Request URL
Qwen-Audio-Live supports only workspace-specific domains. Enter the Workspace ID for Singapore.
wss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtime?model=qwen-audio-3.1-liveRequest Headers
Query Parameters
The model=qwen-audio-3.1-live in the URL selects the service endpoint for Qwen-Audio-Live. After establishing the connection, select a frontend speech model via session.update’s session.model. Valid values are listed in session.update.
Establish a Session and Exchange Audio
- Establish the connection and send
session.update; then wait forsession.updated. - Omit
transportin the session configuration and use the same WebSocket connection for both audio transmission and reception. Upload Base64-encoded PCM audio frame-by-frame viasession.input_audio.append: 16 kHz, 16-bit, mono. Decode the Base64 data insession.output_audio.deltainto 24 kHz, 16-bit, mono PCM audio. - Read input transcription and output subtitles separately via
session.input_transcript.deltaandsession.output_transcript.delta. - Send
session.closeand release resources upon receivingsession.closed.
Task Processing
| Mode | Task Interaction |
|---|---|
| Client | Execute the task upon receiving session.delegation.created and return results via session.commentary.append. The frontend model may continue responding via voice. |
| Responses | Read backend events from response.event. The inner response.completed indicates that backend generation has completed. Receive frontend voice replies via session.output_audio.delta. |
When the frontend model requests a function call, the application receives session.event. After execution, send session.item.create to return the result. Event formats are detailed in Client Events and Server Events.
For a recording demo, see Quickstart. For production integration, see Task Delegation and Tools. For independent media connections to exchange audio, see WebRTC access or AOQ access.
Error Handling
Upon receiving error, verify the request using the error code. Upon receiving session.closed, stop sending events. To resume the conversation, establish a new connection and reconfigure the session.