This article describes the endpoint URL, request headers, and interaction flow for accessing the Paraformer Real-Time Speech Recognition service over a WebSocket connection.
Endpoint URL
Paraformer is supported only in the China (Beijing) region. The WebSocket URL is fixed as follows:
wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference
When making calls, replace {WorkspaceId} with your actual Workspace ID.
Request headers
Add the following information to the request headers:
Parameter | Type | Required | Description |
|---|---|---|---|
Authorization | string | Yes | The authentication token, in the format |
user-agent | string | No | The client identifier, which helps the server track the request source. |
X-DashScope-WorkSpace | string | No | The Alibaba Cloud Model Studio workspace ID. |
X-DashScope-DataInspection | string | No | Whether to enable the data compliance detection feature. By default, this parameter is not passed or is set to |
Interaction flow
For detailed descriptions of client events and server events, see Client events and Server events.
- Establish a connection: The client establishes a WebSocket connection with the server.
- Start the task: The client sends the run-task instruction to start the task and receives the task-started event returned by the server, indicating that the task has been successfully started and subsequent steps can proceed.
- Send the audio stream: The client starts sending binary audio (which must be mono audio) and simultaneously receives the result-generated events continuously returned by the server. These events contain speech recognition results.
- Notify the server to end the task: The client sends the finish-task instruction to notify the server to end the task and continues to receive the result-generated events returned by the server.
- Task ends: The client receives the task-finished event returned by the server, marking the end of the task.
- Close the connection: The client closes the WebSocket connection.