One-shot Speech Recognition

The one-shot speech recognition API provides low-latency real-time recognition for short speech scenarios over the WebSocket protocol.
WSS/v2/ws/asr/oneshot
API codea2t_oneshot
ProtocolWebSocket (text JSON + binary audio)
Gateway path/v2/ws/asr/oneshot
ResponseJSON

Authorization

AuthorizationstringheaderRequired
HTTP: Bearer Auth

Connection

URL

Use the following URL to establish a WebSocket connection:

wss://{gateway-host}/v2/ws/asr/oneshot?model={model_id}

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

  1. Open WebSocket
  2. Send text start
  3. Send binary audio frames in a loop (Chinese, Chinese dialects, and English: up to 75 s; other foreign languages: up to 30 s)
  4. Send text end (optional when server_vad=true and utterance ended)
  5. 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 stage. Fixed value: start.

request_idstring

Session ID. The response sid matches this value; alias: requestId. Defaults to trace_id when omitted.

formatstring

Audio format. Default: pcm. Accepted values: pcm, opus, adpcm, speex, amr.

samplestring

Sample rate. Default: 16k. Accepted values: 16k.

enable_auto_langstring

Whether to enable automatic language detection. Default: false. Accepted values: true, false.

languagestring

Specify language. Accepted values:
  • 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

Whether to return interim results. Default: true. Accepted values: true, false.

punctuationstring

Whether to enable punctuation. Default: true. Accepted values: true, false.

post_procstring

Whether to normalize numbers into Arabic numerals. Default: true. Accepted values: true, false.

server_vadstring

Whether to enable server-side VAD. Default: false. Accepted values: true, false.

max_start_silencestring

Maximum start silence in ms. Default: 2000. Accepted values: positive integers.

max_end_silencestring

Maximum end silence in ms. Default: 500. Accepted values: 200~2000.

contextstring

Context information passed to the model. Maximum length: 500 characters.

hotwordsstring[ ]

Hotword list. Up to 500 items; each hotword is at most 5 Chinese characters or English words.

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

Status code and details of this request

base_resp.status_codeintegerRequired

Status code, 0 means success

base_resp.status_msgstringRequired

Status details; success when "success"

sidstringRequired

Same as request_id

typestring

Result type: fixed / variable

textstring

Current segment text

varTextstring

Variable text

showTextstring

Display text (historical fixed + current segment)

endbooleanRequired

true when the session recognition ends

server_vadbooleanRequired

true when result is triggered by server VAD end

vad_countintegerRequired

VAD segment count

resultNumintegerRequired

Result index, starting at 1

languagestring

Recognized language. Present only when type is fixed. Same values as the request language parameter.

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 CodeDescriptionSolution
202001param error:xxCheck parameters
202002idle timeout error: xxConnection idle timeout
202003server internal error: xxContact support and submit a ticket with the request_id
202004asr timeout error: xxRecognition timeout: Chinese, Chinese dialects, and English up to 75 s; other foreign languages up to 30 s
202005decode error: xxAudio decode failure