Connect to the Fun-ASR real-time speech recognition service over WebSocket. This topic covers the service endpoints, request headers, and interaction flow.
User guide: For an introduction to the model and selection guidance, see Speech-to-text. For sample code, see Real-time speech recognition.
The DashScope SDK supports Java and Python only. For other languages, connect to the service directly over WebSocket.
Service endpoint
Use one of the following WebSocket URLs:
China (Beijing)
wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference
Replace {WorkspaceId} with your actual workspace ID.
Singapore
wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inference
Replace {WorkspaceId} with your actual Workspace ID.
Alibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing) and Singapore regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
China (Beijing): from
dashscope.aliyuncs.comto{WorkspaceId}.cn-beijing.maas.aliyuncs.comSingapore: from
dashscope-intl.aliyuncs.comto{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
Replace {WorkspaceId} with your actual Workspace ID. The existing domains remain fully functional.
The URL must use the wss:// protocol. Provide your API key in the Authorization request header (see Request headers).
Request headers
Include the following headers in your request:
|
Parameter |
Type |
Required |
Description |
|
Authorization |
string |
Yes |
Authentication token in the format |
|
user-agent |
string |
No |
Client identifier that the server uses to trace the request origin. |
|
X-DashScope-WorkSpace |
string |
No |
Alibaba Cloud Model Studio workspace ID. |
|
X-DashScope-DataInspection |
string |
No |
Whether to enable data inspection. Omit this header by default; set it to |
The Authorization header is validated during the WebSocket handshake. If the API key is invalid or missing, the handshake fails with HTTP 401 or 403.
Interaction flow
For detailed descriptions of client events and server events, see Client events and Server-side events.
The client and server exchange messages in the following sequence:
-
Establish a connection: The client opens a WebSocket connection to the server.
-
Start the task: The client sends a
run-taskdirective and waits for the server'stask-startedevent, which indicates that the task is ready and the client can proceed to the next steps. -
Send the audio stream: The client streams binary audio (mono only) while continuously receiving
result-generatedevents from the server. Each event contains speech recognition results. -
Signal task completion: The client sends a
finish-taskdirective to instruct the server to end the task, and continues to receiveresult-generatedevents. -
End the task: The client receives a
task-finishedevent from the server, which signals that the task has ended. -
Close the connection: The client closes the WebSocket connection.