One-shot Speech Recognition
| API code | a2t_oneshot |
| Protocol | WebSocket (text JSON + binary audio) |
| Gateway path | /v2/ws/asr/oneshot |
| 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 default request_id
Handshake headers (client → gateway)
AuthorizationRequired
Bearer {api_key}
ConnectionRequired
Upgrade
UpgradeRequired
websocket
Handshake failure (WebSocket not established)
Returns HTTP 401 / 429 etc
Session flow
- Open WebSocket
- Send text start
- Send binary audio frames in a loop (Chinese, Chinese dialects, and English: up to 75 s; other foreign languages: up to 30 s)
- Send text end (optional when server_vad=true and utterance ended)
- Receive text until end=true
Audio sent before start is discarded.
Client messages
Text frame: start
Flat JSON root (no data wrapper). Booleans are strings "true" / "false" (case-insensitive).
typestringRequired
request_idstring
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
server_vadstring
max_start_silencestring
max_end_silencestring
contextstring
hotwordsstring[ ]
Binary frame: audio
- Type: WebSocket Binary
- Content: Encoded audio chunks matching start.format (not Base64)
- Decode: Server decodes to PCM 16 kHz mono before recognition
- Duration: Chinese, Chinese dialects, and English: up to 75 seconds; other foreign languages: up to 30 seconds.
Text frame: end
{
"type": "end"
}Only start and end are supported; other type values return param error.
Server response
base_respobjectRequired
base_resp.status_codeintegerRequired
base_resp.status_msgstringRequired
sidstringRequired
typestring
textstring
varTextstring
showTextstring
endbooleanRequired
server_vadbooleanRequired
vad_countintegerRequired
resultNumintegerRequired
languagestring
End example
{
"base_resp": {
"status_code": 0,
"status_msg": "success"
},
"sid": "trace-abc-001",
"type": "fixed",
"text": "你好世界。",
"showText": "你好世界。",
"end": true,
"server_vad": false,
"vad_count": 0,
"resultNum": 2,
"language": "zh-CN"
}Error codes
| Business Error Code | Description | Solution |
|---|---|---|
| 202001 | param error:xx | Check parameters |
| 202002 | idle timeout error: xx | Connection idle timeout |
| 202003 | server internal error: xx | Contact support and submit a ticket with the request_id |
| 202004 | asr timeout error: xx | Recognition timeout: Chinese, Chinese dialects, and English up to 75 s; other foreign languages up to 30 s |
| 202005 | decode error: xx | Audio decode failure |