This service uses the WebSocket protocol to recognize a real-time audio stream and return recognition results synchronously, so text appears as the speaker talks.
Note:
Starting September 24, 2026, new users should use this document to integrate the new v3 API.
Users who have already integrated the legacy WebSocket v2 protocol can refer to WebSocket Access (Legacy) for details.
Used to generate the UserSig; never transmitted over the network.
Note:
For the international site, sign up at trtc.io (a Tencentcloud account is created automatically; no real-name verification is required), create an application in the TRTC Console, and activate "AI Speech Recognition". This service is only available with an RTC Engine Lite (or higher) monthly subscription; Free Trial is not supported. See Activate the Service.
API Requirements
Item
Description
Languages
Mandarin Chinese, Chinese dialects, English, and other languages such as Japanese, Korean, and French.
1 pcm, 4 speex, 6 silk, 8 mp3, 10 opus (raw Opus frame stream), 11 ogg (Ogg container, including .opus/.ogg files), 12 wav, 14 m4a, 16 aac.
Note:
Opus is a codec, and there are two ways to package it for transmission, corresponding to different voice_format values:
10 (raw Opus frame stream): the audio is a continuous sequence of Opus frames, each preceded by a 2-byte little-endian length prefix.
11 (Ogg container): the audio is an Ogg container file whose first 4 bytes are OggS. Common .opus and .ogg files fall into this category (the codec inside the container may be Opus or Vorbis). When streaming an existing audio file, choose 11.
To check, look at the first 4 bytes of the file: if they are OggS, use 11.
Protocol
WSS.
Endpoint
wss://asr-intl.cloud-rtc.com/asr/v3?voice_id=<voice_id>; Authentication information is passed in the auth block of the first message. The URL carries no authentication parameters.
Response format
JSON.
Data sending
Send a 40 ms audio packet every 40 ms (a 1:1 real-time rate). The corresponding PCM size is 640 bytes at 8 kHz and 1280 bytes at 16 kHz. A single frame must not exceed 256 KB. After the connection is established, the first message must be sent within 3 seconds. If the interval between audio packets exceeds 15 seconds, the backend returns an error and closes the connection.
Concurrency limit
By default, a single account (SDKAppID) is limited to 100 concurrent streams.
Note:
If you need higher concurrency, please contact us.
Flow Chart
Corresponding SDK behavior: Start() completes steps 1 and 2 (it waits synchronously for the ack, and returns an error immediately on authentication or parameter errors); Write() corresponds to the step 3 upstream audio; downstream messages are delivered through listener callbacks OnSentenceBegin / OnRecognitionResultChange / OnSentenceEnd / OnRecognitionComplete; Stop() sends end and waits for final:1.
API Call Flow
The call flow has three phases: connection, authentication, and recognition. In the authentication and recognition phases, the backend returns text messages whose content is a JSON-serialized string. Common fields are described below:
Field
Type
Description
code
Integer
Status code. 0 means success; a non-zero value indicates an error.
message
String
Error description.
voice_id
String
Globally unique ID of the audio stream; one WebSocket connection corresponds to one voice_id. Generated by the user (a UUID is recommended), up to 128 characters.
When this field is 1, recognition of the whole audio stream has finished.
Connection Phase
The client initiates a WebSocket connection request. The request URL format is: wss://asr-intl.cloud-rtc.com/asr/v3?voice_id=<voice_id>.
The URL carries only voice_id and no authentication parameters. voice_id appears both in the URL ?voice_id= and in the first-message params.voice_id; the two must be identical, or it can be omitted from params. The SDK generates a UUID by default; you can specify one with SetVoiceID.
Authentication Phase
After the connection is established, the client must send a first text message within 3 seconds. Its content is JSON and it carries both authentication and parameters:
Type is always start. If the first-message JSON is invalid or type is not start, the server returns 4010; if the first message is not sent within 3 seconds, it returns 4008.
After authentication succeeds, the server returns an acknowledgment with code 0:
If authentication or parameter validation fails, the server returns an error frame with a non-zero code (such as 4002 for authentication failure or 4001 for invalid parameters) and then closes the connection normally.
The SDK's Start() waits synchronously for this ack, so authentication and parameter errors are returned directly from Start().
auth Fields
One WebSocket connection is one stream. voice_id is both the stream identity and the signature identifier, so it is not repeated in the auth block.
Field
Type
Required
Description
sdkappid
String
Yes
TRTC application ID, taken from the credential and filled in automatically by the SDK.
usersig
String
Yes
TRTC signature; identifier = the current voice_id, and the SDK signs with that value. For how to calculate it, see Authentication & UserSig.
Note:
The online protocol has no request_id. request_id is a concept of the offline APIs, where "one request = one transaction"; it does not exist in the streaming protocol.
Signature Rules
1. If credential.SetUserSig() is not called, the SDK generates the signature locally from SDKAppID + SecretKey. It is valid for 86400 seconds and is regenerated for every connection, so long-running services do not need to manage expiry.
2. If you pass a fixed signature with credential.SetUserSig(sig), the SDK no longer generates or refreshes it. The server verifies the signature against the current identifier (voice_id for online), so the signature must be issued with the same identifier. In fixed-signature scenarios (such as a browser receiving a signature from your backend), you must handle expiry and identifier alignment yourself.
3. Signatures are bound to the site. SetSite(common.SiteIntl) determines the host and the verification cluster; international-site credentials cannot be used on the China site, and vice versa.
4. SecretKey is never transmitted over the network; the signature is only used for server-side verification.
params Fields
Parameter
Required
Type
Description
voice_id
No
String
Globally unique ID of the audio stream; one WebSocket connection corresponds to one. Generated by the user (a UUID is recommended), up to 128 characters. Must match the URL parameter, or be omitted.
Other languages: ar (Arabic), de (German), fr (French), es (Spanish), pt (Portuguese), id (Indonesian), it (Italian), ko (Korean), ru (Russian), th (Thai), vi (Vietnamese), ja (Japanese), tr (Turkish), hi (Hindi), ms (Malay), nl (Dutch), sv (Swedish), da (Danish), fi (Finnish), pl (Polish), cs (Czech), fa (Persian), el (Greek), ro (Romanian), hu (Hungarian), mk (Macedonian).
Speech Recognition 1.0
Basic: 8k_zh supports Mandarin and Chinese dialects.
Standard: 8k_zh_large and 16k_zh_large support Mandarin and Chinese dialects; 16k_zh_en supports Mandarin, Chinese dialects, English, and mixed Chinese-English.
Advanced: vi (Vietnamese), ja (Japanese), ko (Korean), id (Indonesian), th (Thai), pt (Portuguese), tr (Turkish), ar (Arabic), es (Spanish), hi (Hindi), fr (French), ms (Malay), fil (Filipino), de (German), it (Italian), ru (Russian), sv (Swedish), da (Danish), no (Norwegian).
If you need more languages, please contact us for evaluation.
Note:
When engine_model_type is bigmodel and language is omitted, the model detects the language automatically; when using the SDK, we recommend setting it explicitly.
Opus is a codec, and there are two ways to package it, corresponding to different values. 10 raw Opus frame stream: a continuous sequence of Opus frames, each preceded by a 2-byte little-endian length prefix; 11 Ogg container: an Ogg container file whose first 4 bytes are OggS; common .opus and .ogg files belong here (the codec inside may be Opus or Vorbis). When streaming an existing audio file, choose 11.
To check, look at the first 4 bytes of the file: if they are OggS, use 11.
For real-time streaming, pcm (16 kHz, 16-bit, mono) is recommended.
input_sample_rate
No
Integer
Upsamples 8 kHz PCM audio to 16 kHz before recognition when it does not match the engine sample rate, which effectively improves accuracy. Only 8000 is supported.
Note:
This parameter only applies to PCM audio. If omitted, the default applies: the engine sample rate is assumed to equal the PCM audio sample rate.
needvad
No
Integer
0 turn VAD off.
1 turn VAD on.
If omitted, the engine decides (the Go SDK sends 1 by default). To ensure recognition quality, speech segments longer than 60 seconds are forcibly split at 60 s; enabling VAD (voice activity detection and segmentation) is recommended for audio longer than 60 s to improve splitting.
vad_silence_time
No
Integer
Sentence-break detection threshold: a silence longer than this value is treated as a sentence break (mostly used in intelligent customer service; use together with needvad=1). Range 240-2000 (default 800), in ms. Changing this parameter is not recommended, as it may affect recognition quality.
vad_level
No
Integer
VAD scenario level:
0 high recall.
1 far-field filtering.
Default 1. Setting noise_threshold overrides this level.
noise_threshold
No
Float
Noise threshold, range [0.0, 4.0]. For some audio segments, a larger value makes it more likely to be judged as noise; a smaller value makes it more likely to be judged as human voice. If omitted, the server default applies.
speaker_diarization
No
Integer
Real-time speaker diarization:
0 off.
1 on (anonymous clustering).
3 on, plus role authentication; use together with voiceprint_ids or speaker_roles.
Default 0.
Note:
When set to 1 or 3, the server forces VAD on and adjusts word_info.
enable_speaker_context
No
Integer
Resume speaker diarization from a breakpoint:
0 off;
1 return the recovery state synchronously;
2 return immediately in the first response (ID only);
Use together with speaker_diarization=1/3.
voiceprint_ids
No
String Array
IDs of registered voiceprints to match in real time. The values are obtained through the voiceprint registration API. It is an array supporting up to 32 voiceprints. Takes effect only when speaker_diarization=3. Example: ["550e8400-e29b-41d4-a716-446655440000","550e8400-e29b-41d4-a716-446655440002"].
speaker_roles
No
Object Array
Temporary voiceprints, valid only for this recognition and only when speaker_diarization=3. Format: [{"audio_url":"...","role_name":"..."}]. When matched, role_name is echoed in the speaker_name of the recognition result.
max_speak_time
No
Integer
Forced sentence break, range 5000-90000 (in ms), default 60000. When speech continues without a pause, this parameter forces a sentence break (the result becomes stable, slice_type=2). For example, in game commentary where the commentator speaks continuously, setting this to 10000 produces a slice_type=2 callback every 10 seconds.
filter_dirty
No
Integer
Whether to filter profanity (Mandarin only). Default 0.
0 do not filter.
1 filter.
2 replace with *.
filter_modal
No
Integer
Whether to filter modal particles (Mandarin only). Default 0.
0 do not filter.
1 partial filtering.
2 strict filtering.
filter_punc
No
Integer
Whether to filter the period at the end of a sentence (Mandarin only). Default 0.
0 do not filter.
1 filter.
filter_empty_result
No
Integer
Whether to deliver empty results:
0 deliver.
1 do not deliver.
Default 1.
convert_num_mode
No
Integer
Whether to intelligently convert numbers to Arabic numerals:
0 no conversion, output Chinese numerals directly.
1 convert intelligently based on context.
3 math mode.
Default 1.
word_info
No
Integer
Whether to show word-level timestamps:
0 no.
1 yes, without punctuation timestamps.
2 yes, with punctuation timestamps;
100 subtitle mode.
Default 0.
word_with_space
No
Integer
Whether to output spaces between English words. Default 0.
hotword_id
No
String
Hotword list ID (SDKAppID scope). Create the hotword list in the console first.
hotword_list
No
String
Temporary hotword list to improve recognition accuracy. Single hotword format: "hotword|weight". Each hotword must not exceed 30 characters (or 10 Chinese characters). Supported weights: 1-11 or 100. For example: "Tencent|5" or "ASR|11". Multiple hotwords must be separated by commas. A maximum of 128 hotwords is supported. For example: "hotword|10,Tencent|5,ASR|11".
Note:
A weight of 11 upgrades the hotword to a super hotword. Use this weight only for important terms that must take effect; configuring too many super hotwords may reduce overall recognition accuracy. A weight of 100 enables enhanced homophone replacement.
For example, if "site|100" is configured, recognition results such as "sight" or "cite", which share the same pronunciation, are forcibly replaced with "site". Use this setting only for important terms that must take effect; configuring too many such hotwords may reduce overall recognition accuracy. Hotwords cannot contain spaces.
Recognition Phase
Uploading Data
After authentication succeeds, the client keeps uploading binary messages to the backend containing the audio stream. Send a 40 ms audio packet every 40 ms (a 1:1 real-time rate); the PCM size is 640 bytes at 8 kHz and 1280 bytes at 16 kHz. A single frame must not exceed 256 KB. If the interval between audio packets exceeds 15 seconds, the backend returns 4008 and closes the connection.
When the audio stream has been fully uploaded, the client must send the following text message to tell the backend to finish recognition.
{"type":"end"}
Receiving Messages
While uploading, the client must receive real-time recognition results from the backend at the same time. Example result:
1 a sentence is being recognized, voice_text_str is an unstable result (it may still change).
2 a sentence has been recognized, voice_text_str is a stable result (it will not change).
Depending on the audio sent, the slice_type sequences that may be returned are:
0-1-2 (sentence start, recognition in progress with possibly several 1 returns, sentence end).
0-2.
Or a direct 2 (the complete recognition result of a sentence).
index
Integer
Sequence number of this sentence in the whole audio stream, starting from 0 and increasing sentence by sentence.
start_time
Integer
Start time of this sentence in the whole audio stream.
end_time
Integer
End time of this sentence in the whole audio stream.
voice_text_str
String
Text result of this sentence, UTF-8 encoded.
language
String
Language recognized for this sentence, for example zh.
word_size
Integer
Number of words in this sentence (equal to the length of the word_list array).
word_list
Word Array
Word list of this sentence; see the structure below. Requires word_info != 0.
speaker_segments
SpeakerSegment Array
Returned when real-time speaker diarization is enabled; the speaker segments of the current sentence.
finish_silence_ms
Integer
Length of trailing silence (ms) that triggered the sentence break.
last_token_runtime_ms
Integer
Server decoding time of the last character (ms).
Word Structure
Field
Type
Description
word
String
Content of the word.
start_time
Integer
Start time of the word in the whole audio stream.
end_time
Integer
End time of the word in the whole audio stream.
stable_flag
Integer
Stability of the word:
0 the word may change in later recognition.
1 the word will not change in later recognition.
speaker_id
Integer
Present when real-time speaker diarization is enabled.
-1 unknown speaker.
>0 speaker ID.
speaker_name
String
Identifier of the registered-voiceprint speaker.
Speaker Diarization
After speaker_diarization is enabled, speaker labels are returned through two entry points:
result.speaker_segments[](recommended): one result may contain several speakers, and sentence-level attribution is inherently ambiguous, so the protocol returns results split into segments by speaker. len(speaker_segments) == 1 means a single-speaker sentence.
result.word_list[].speaker_id: word-level attribution; word_info != 0 must also be set.
speaker_id semantics: valid within a session, numbered from 1; -1 means unknown speaker; 0 is reserved.
speaker_segments Fields
Field
Type
Description
speaker_id
Integer
Speaker ID.
-1 unknown speaker.
>0 speaker ID.
speaker_name
String
Identifier of the registered-voiceprint speaker. Returned only when speaker_diarization=3 and a registered voiceprint is matched; equal to the request-side role_name.
start_time
Integer
Segment start time (ms).
end_time
Integer
Segment end time (ms).
text
String
Text of this segment.
word_start
Integer
Start index into word_list (inclusive). Not returned when word_info=0.
word_end
Integer
End index into word_list (inclusive), i.e. word_list[word_start:word_end+1]. Not returned when word_info=0.
stable_flag
Integer
Whether the result is stable:
1 stable.
0 unstable.
VAD Tuning
Method
Value
Description
SetVadLevel(level)
0 / 1
0 high recall.
1 far-field filtering (server default).
SetNoiseThreshold(v)
0.0 - 4.0
Fine-tunes noise suppression: the larger the value, the stronger the suppression and the lower the recall. Once set, it overrides the vad_level level.
SetVadSilenceTime(ms)
240 - 2000
Silence threshold for sentence breaks.
Both are tri-state: they are sent only when the setter is called explicitly, so an explicit 0 can be distinguished from "not configured" (the server default for vad_level is 1). Out-of-range values cause a local error at Start() and do not waste a connection.
Developer Resources
Installation
go get github.com/Tencent-RTC/trtc-asr-sdk-go@latest
Custom voice_id (the UserSig is bound to this value automatically).
Auto UUID
Error Codes
Code
Description
4000
Too much audio data sent.
Note:
Real-time recognition works as "text appears while speaking"; the total duration of audio sent within 1 second should be 1 second.
4001
Invalid parameter; see message for details.
4002
Authentication failed. Check that sdkappid and usersig were passed correctly in the auth block of the first message, that the signature identifier equals the current voice_id, and that the signature is valid and not expired.
4003
The service is not activated for this AppID. Activate it in the console.
4004
Resource package exhausted. Enable pay-as-you-go billing or purchase a resource package.
4005
Service stopped because the account is overdue. Please top up promptly.
4006
The account's current concurrent calls exceed the limit.
4007
Audio decoding failed. Check that the uploaded audio format matches the call parameters.
4008
Timeout. The first message was not sent within 3 seconds after the connection was established, or no audio was sent for 15 seconds during recognition.
4009
Client connection disconnected.
4010
Client uploaded an unknown text message. The first-message JSON is invalid, or type is not start.
5000
Failure caused by high server load, network jitter, etc. Please start a new recognition.
Note:
This is usually transient. A small number of occurrences can be ignored; just start a new recognition.
5001
Same as 5000.
5002
Same as 5000.
SDK local error codes: The error returned by the SDK is *common.ASRError, and its Code is the server error code. Local SDK errors use the 10xx range, for example 1001 (local parameter error) and 1002 (connection failed).