Access the Qwen-Audio-TTS/CosyVoice real-time speech synthesis service through a WebSocket connection. Covers service endpoints, request headers, and the client-server interaction workflow.
The DashScope SDK supports Java and Python only. For other languages, use a WebSocket connection.
User guide: Speech synthesis covers model details and selection guidance.
Rate limits: Model calls are subject to rate limits. When a limit is exceeded, the server returns the error
Fixed WebSocket URL:
Include the following headers in the request:
For details about client-side and server-side events, see Client events and Server-side events.
Client-server interaction sequence:
Requests rate limit exceeded, please try again later. Reduce your request rate or concurrency and retry. For the rate limits of each model, see Rate limiting.
Service endpoints
Fixed WebSocket URL:
- Singapore
- China (Beijing)
wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inferenceReplace {WorkspaceId} with your actual workspace ID.Request headers
Include the following headers in the request:
Parameter | Type | Required | Description |
|---|---|---|---|
Authorization | string | Yes | Format: |
user-agent | string | No | Client identifier for request tracking. |
X-DashScope-WorkSpace | string | No | Alibaba Cloud Model Studio workspace ID. |
X-DashScope-DataInspection | string | No | Enables data inspection. Default: |
Interaction workflow
- Establish a connection: Create a WebSocket connection to the server.
- Start a task: Send a run-task event.
- Wait for confirmation: Receive a task-started event from the server before proceeding.
-
Send text for synthesis:
Send one or more continue-task events with the text to synthesize, in sequence. The server returns a result-generated event with an audio stream after each complete sentence. For text length limits, see the
textfield in the continue-task event.Send multiple continue-task events with text segments in order. The server splits text into sentences:- Complete sentences are synthesized and returned as audio immediately.
- Incomplete sentences are buffered until complete.
-
Receive audio: Read the audio stream from the
binarychannel. - End the task: After sending all text, send a finish-task event and continue receiving audio. This step is mandatory — skipping it may produce incomplete audio.
- Receive task completion: A task-finished event from the server confirms the task is complete.
- Close the connection: Disconnect the WebSocket.