Connect to the Qwen-TTS real-time speech synthesis service over WebSocket. Covers the service endpoint, request headers, and interaction flow.
For model overview and selection guidance, see Real-time speech synthesis
The Qwen-TTS Realtime API uses the WebSocket protocol. Java and Python applications can use the DashScope SDK to skip WebSocket handling. Other languages can connect with a WebSocket library directly.
Service endpoint
Use the following URL. Set the model with the model query parameter:
Singapore
WebSocket URL: wss://dashscope-intl.aliyuncs.com/api-ws/v1/realtime?model=qwen3-tts-flash-realtime
China (Beijing)
WebSocket URL: wss://dashscope-intl.aliyuncs.com/api-ws/v1/realtime?model=qwen3-tts-flash-realtime
The URL must use the wss:// protocol. Set the Authorization header (see Request headers) and specify the model using the model query parameter.
Request headers
Set the following request headers:
|
Parameter |
Type |
Required |
Description |
|
Authorization |
string |
Yes |
Format: |
|
user-agent |
string |
No |
Client identifier for server-side source tracking. |
|
X-DashScope-WorkSpace |
string |
No |
The Alibaba Cloud Model Studio workspace ID. |
Authorization is verified during the WebSocket handshake. An invalid or missing API key causes the handshake to fail with HTTP 401/403.
Interaction flow
For detailed descriptions of client events and server events, see Client events and Server events.
The API supports two modes:
-
ServerCommit mode: The server determines text segmentation and synthesis timing automatically.
-
Commit mode: The client controls when to submit each text segment. Call
input_text_buffer.commitexplicitly to trigger synthesis.
Mode details
-
In ServerCommit mode, call
input_text_buffer.appendto buffer text. The system determines synthesis timing automatically. -
Calling
input_text_buffer.commitin ServerCommit mode synthesizes the current buffer immediately. The session then resumes ServerCommit mode. -
In Commit mode,
input_text_buffer.appendalone does not trigger synthesis. Callinput_text_buffer.committo start synthesis.
Key steps:
-
Connection: The client opens a WebSocket connection. The server returns
session.createdwhen ready. -
Session configuration: The client sends
session.updateto configure voice, format, and mode. -
Text input: The client sends
input_text_buffer.appendto add text to the buffer. -
Synthesis trigger:
-
In ServerCommit mode, synthesis starts automatically. The client can call
input_text_buffer.committo force immediate synthesis. -
In Commit mode, only
input_text_buffer.committriggers synthesis.
-
-
Audio generation: The server sends
response.created, then streams base64-encoded audio asresponse.audio.deltaevents untilresponse.audio.done. -
Session termination: The client sends
session.finishto release resources. The server returnssession.finishedand closes the connection.
After connection, the server returns this session.created event:
{
"event_id": "event_xxx",
"type": "session.created",
"session": {
"object": "realtime.session",
"mode": "server_commit",
"model": "qwen3-tts-flash-realtime",
"voice": "Cherry",
"response_format": "pcm",
"sample_rate": 24000,
"id": "sess_xxx"
}
}