Use a WebSocket connection to access the Sambert real-time speech synthesis service. This topic covers the service endpoint, request headers, and interaction workflow.
Service endpoint
Sambert is available only in the Beijing region.
The WebSocket service endpoint is: wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference
Replace {WorkspaceId} with your actual workspace ID.
Request headers
Include the following headers in the request:
Parameter | Type | Required | Description |
|---|---|---|---|
Authorization | string | Yes | Authorization token in the format |
user-agent | string | No | Client identifier for server-side request tracking. |
X-DashScope-WorkSpace | string | No | The workspace ID of Alibaba Cloud Model Studio. |
X-DashScope-DataInspection | string | No | Controls data inspection. Data inspection is enabled by default when this parameter is not set. Set it to |
Interaction workflow
- Establish a connection: The client establishes a WebSocket connection with the server.
- Start a task: The client sends a run-task event to start a task. Sambert sends all text to synthesize in a single run-task event.
- Wait for confirmation: The client receives a task-started event from the server, which indicates that the task has started.
- Receive audio: The client receives an audio stream from the server over the
binarychannel. The client also receives result-generated events that carry additional information such as timestamps. - Complete the task: The client receives a task-finished event from the server, which indicates that the task is complete.
- Close the connection: The client closes the WebSocket connection.