Real-time Speech Transcription

The Real-time Speech Transcription API provides stable streaming transcription for long-form speech scenarios over the WebSocket protocol.
WSS/v2/audio/asr/realtime
API codea2t_realtime
ProtocolWebSocket (text JSON + binary audio)
Gateway path/v2/audio/asr/realtime
ResponseJSON

Authorization

AuthorizationstringheaderRequired
HTTP: Bearer Auth

Connection

URL

Use the following URL to establish a WebSocket connection:

wss://{gateway-host}/v2/audio/asr/realtime?model={model_id}

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

  1. Open WebSocket
  2. Send text start
  3. Send binary audio frames in a loop
  4. Send text end
  5. 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

Request stage. Fixed value: start.

dataobject

Business parameter object for the start frame.

All fields below live under the data object.

formatstring

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

samplestring

Sample rate. Default: 16k. Accepted values: 16k. Also accepts 16000.

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.

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.

speaker_separatestring

Whether to enable speaker separation. Default: false. Accepted values: true uses the Yama engine; false uses the streaming Stream engine.

text_smoothingstring

Text smoothing (valid only when speaker separation is enabled). Default: false. Accepted values: true, false.

speaker_idsstring[ ]

Registered voiceprint IDs (valid only when speaker separation is enabled), up to 10 supported

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

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

Session ID, equals trace_id

typestring

variable (interim) / fixed (stable or utterance end)

textstring

Current segment text

start_timelong

Utterance start time (ms); null when type=variable

end_timelong

Utterance end time (ms); null when type=variable

wordInfoarray

Word boundaries, returned when type=fixed

speakerstring

Returned only when speaker_separate=true is passed in start and type=fixed

rms_energynumber

RMS energy, range [0.0, 1.0]

languagestring

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

endbooleanRequired

true when this recognition round ends

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 CodeDescriptionSolution
203001param error:xxCheck parameters
203002idle timeout error: xxConnection idle timeout
203003server internal error: xxContact support and submit a ticket with the request_id
203004process error:: xxContact support and submit a ticket with the request_id
203005decode error: xxAudio decode failure