Nuwa ASR real-time speech recognition protocol
1. Overview
Nuwa ASR provides real-time speech recognition over WebSocket. Clients stream audio to the ASR service and receive recognition results as they become available.
2. Before integration
- Obtain the WebSocket URL for the ASR service from the Nuwa platform.
- Audio is typically raw, mono PCM sampled at 16 kHz.
- Select the recognition engine with
stype:doubao(default) ordiy.
3. Connection URL
WebSocket connection
wss://wsapi.nuwaai.com/websk/humanAgent/realasr
wss://wsapi.nuwaai.com/websk/humanAgent/realasr/{stype}
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| stype | String | No | Recognition service type: doubao (default) or diy. |
Tips
If stype is omitted, the server uses the doubao engine.
4. Connection example
示例
const host = 'wss://your-asr-server.example.com';
const stype = 'doubao';
const ws = new WebSocket(`${host}/realasr/${stype}`);
ws.onopen = () => console.log('ASR WebSocket connected');
ws.onmessage = (event) => console.log('ASR message received:', JSON.parse(event.data));
ws.onclose = () => console.log('ASR WebSocket closed');
ws.onerror = (err) => console.error('ASR WebSocket error:', err);
5. Client messages
5.1 Text control messages
Send a JSON message to configure recognition hot words:
{
"type": "setHotWords",
"data": { "hotWords": ["hello", "take a break", "how are you"] }
}
| Name | Type | Required | Description |
|---|---|---|---|
| type | String | Yes | Message type, currently setHotWords. |
| data | Object | Yes | Message payload. |
| data.hotWords | Array | No | List of hot-word strings. |
Tips
The server forwards hot words to the ASR engine to improve recognition accuracy.
5.2 Binary audio messages
Send audio data as binary WebSocket messages:
- Send raw audio bytes (for example, a
bytes/ArrayBuffervalue). - Audio is typically mono PCM at 16 kHz.
// Send an audio chunk
ws.send(audioArrayBuffer);
6. Server messages
The server pushes ASR results as JSON messages. Common message types are:
| Type | Description |
|---|---|
asr-text | Real-time recognition text (partial or full). |
asr-commit | Committed final recognition text. |
checkToEnd | Indicates whether the recognition stage has ended. |
first | First-frame or first-segment result. |
asr-error | ASR recognition error. |
Example: recognition result
{ "type": "asr-text", "data": { "content": "The weather is nice today" } }
Example: final result
{ "type": "asr-commit", "data": { "content": "The weather is nice today" } }
Example: error notification
{ "type": "asr-error", "data": { "message": "Recognition failed", "code": 500 } }
7. Recognition service types
| stype | Description |
|---|---|
doubao | Default engine, using the Doubao ASR service. |
diy | Custom recognition engine, using the DIY ASR service. |
8. Recommended integration flow
- Open a WebSocket connection to
/realasror/realasr/{stype}. - (Optional) Send
setHotWordsto configure hot words. - Stream binary audio data.
- Continue receiving
asr-textandasr-commitmessages. - Close the WebSocket after recognition is complete.
sequenceDiagram
participant C as Client
participant S as ASR service
C->>S: 1. Open WebSocket connection
S-->>C: 2. Confirm connection
C->>S: 3. Send setHotWords (optional)
S-->>S: 4. Update hot-word configuration
loop Stream and recognize audio
C->>S: 5. Send binary audio data
S-->>C: 6. Return asr-text partial result
C->>S: 7. Continue sending audio
S-->>C: 8. Return asr-commit final result
end
C->>S: 9. Close WebSocket connection