Real-time Speech Transcription
| API code | a2t_realtime |
| Protocol | WebSocket (text JSON + binary audio) |
| Gateway path | /v2/audio/asr/realtime |
| Response | JSON |
Authorization
- Security Scheme Type: http
- HTTP Authorization Scheme: Bearer API_key,Used to verify account information, can be viewed in Pay-as-you-go > API Key Management .
Connection
URL
Use the following URL to establish a WebSocket connection:
Query parameters
modelRequired
Available model code option: u2-asr.
trace_idOptional
Trace ID; generated by gateway if omitted, used as sid
Handshake headers (client → gateway)
AuthorizationRequired
Bearer {api_key}
ConnectionRequired
Upgrade
UpgradeRequired
websocket
Handshake failure (WebSocket not established)
Returns HTTP 401 / 429 etc. with JSON body (base_resp). No ResultVO.
{
"base_resp": {
"status_code": 100001,
"status_msg": "..."
}
}Session flow
- Open WebSocket
- Send text start
- Send binary audio frames in a loop
- Send text end
- Receive text until end=true (server closes connection on success)
Audio sent before start is discarded.
Client messages
Text frame: start
Business parameters live under data; defaults to {}. Booleans are strings "true" / "false" (case-insensitive).
typestringRequired
dataobject
Business parameter object for the start frame.
All fields below live under the data object.
formatstring
samplestring
enable_auto_langstring
languagestring
- zh-CN (Chinese)
- en-US (English)
- ar-SA (Arabic)
- de-DE (German)
- es-MX (Spanish)
- fr-FR (French)
- id-ID (Indonesian)
- ja-JP (Japanese)
- ko-KR (Korean)
- pt-BR (Portuguese)
- ru-RU (Russian)
- tr-TR (Turkish)
- vi-VN (Vietnamese)
- th-TH (Thai)
- it-IT (Italian)
variablestring
punctuationstring
post_procstring
contextstring
hotwordsstring[ ]
speaker_separatestring
text_smoothingstring
speaker_idsstring[ ]
Binary frame: audio
- Type: WebSocket Binary
- Content: Encoded audio chunks matching start.data.format (not Base64)
- Timing: Timing: after start succeeds, before end
Text frame: end
{ "type": "end" }Server response
base_respobjectRequired
base_resp.status_codeintegerRequired
base_resp.status_msgstringRequired
sidstringRequired
typestring
textstring
start_timelong
end_timelong
wordInfoarray
speakerstring
rms_energynumber
languagestring
endbooleanRequired
Push rules
- No type=variable when variable=false
- Skip push when text is empty and end=false
- Skip duplicate variable text when variable=true
- On base_resp.status_code≠0, end=true then connection closes
Utterance end example
{
"base_resp": {
"status_code": 0,
"status_msg": "success"
},
"sid": "a1b2c3d4e5f6478990abcdef12345678",
"type": "fixed",
"text": "你好世界",
"start_time": 0,
"end_time": 1200,
"language": "zh-CN",
"end": false
}Session end example
{
"base_resp": {
"status_code": 0,
"status_msg": "success"
},
"sid": "a1b2c3d4e5f6478990abcdef12345678",
"type": "fixed",
"text": "",
"language": "",
"end": true
}Error codes
Gateway handshake errors are documented under Connection; no ResultVO.
| Business Error Code | Description | Solution |
|---|---|---|
| 203001 | param error:xx | Check parameters |
| 203002 | idle timeout error: xx | Connection idle timeout |
| 203003 | server internal error: xx | Contact support and submit a ticket with the request_id |
| 203004 | process error:: xx | Contact support and submit a ticket with the request_id |
| 203005 | decode error: xx | Audio decode failure |