Real-Time Subtitles

Feature Overview

TRTC AI Real-Time Conversation 2.0 enables real-time subtitle display. Subtitles are delivered via TRTC custom messages, allowing millisecond-level synchronization with audio conversations.
To receive real-time AI subtitle data, listen for the experimental interface event webhook and monitor the onAIConversationEvent callback on the client.

Subtitle Reception

Connecting to the Bot

Before invoking subtitle features, ensure you have connected to the bot using connect. For integration details, see: Client: Connecting AI Bot.

Listening for Subtitles

After establishing the connection, subtitles are pushed in real time through the onExperimentalEvent callback, where eventName is onAIConversationEvent. When params.event is asrSubtitle, it refers to the user's speech recognition result. When params.event is llmSubtitle, it refers to the bot's reply text.

Subtitle Modes

Bot subtitle timing is controlled by the AgentConfig.SubtitleMode parameter when creating a task.
SubtitleMode
Description
0 (default)
Display subtitles as soon as possible. The LLM-generated text is returned immediately after generation and is not synchronized with audio playback, so subtitles appear before the audio.
1
Sentence-level synchronization. The complete reply text for the sentence currently being played is returned. The text updates when the current sentence ends and the next begins.

ASR Subtitles

ASR subtitles represent the user's speech recognition result. The text field contains the recognized content of the current sentence so far, and end is true when the sentence recognition is complete.
{
"event": "asrSubtitle",
"robotid": "ai_bot_001",
"data": {
"type": 10100,
"robotid": "ai_bot_001",
"sender": "user_001",
"payload": {
"text": "Hello.",
"start_time_ms": 4446039,
"end_time_ms": 4456039,
"start_utc_ms": 1785396254452,
"end_utc_ms": 1785396264452,
"end": false,
"roundid": "D7E2053C-6E1F-4941-9761-FEE0407016EF",
"taskid": "task-id"
}
}
}
Field
Type
Description
event
String
Fixed value: asrSubtitle.
robotid
String
UserId of the connected AI bot.
data.type
Number
Message type; ASR subtitle is 10100.
data.robotid
String
UserId of the AI conversation bot.
data.sender
String
UserId of the recognized user.
data.payload.text
String
Current recognized text for the sentence.
data.payload.start_time_ms
Number
Start time of the sentence in the audio stream, relative time in milliseconds.
data.payload.end_time_ms
Number
End time of the sentence in the audio stream, relative time in milliseconds.
data.payload.start_utc_ms
Number
UTC timestamp for the start of the sentence, in milliseconds.
data.payload.end_utc_ms
Number
UTC timestamp for the end of the sentence, in milliseconds.
data.payload.end
Boolean
false indicates an interim result; true indicates the sentence recognition is complete.
data.payload.roundid
String
Conversation round ID; used to associate ASR and LLM subtitles within the same round.
data.payload.taskid
String
AI conversation task ID.
Note:
To synchronize subtitles with audio, sort sentences within the same audio stream by start_time_ms. To align with absolute business-side time (such as message send time), use start_utc_ms.

LLM Subtitles

LLM subtitles represent the bot's reply text. The text field contains the full reply for the current round so far, with end set to true when the round's reply is complete. The roundid matches the ASR subtitle that triggered this response.
{
"event": "llmSubtitle",
"robotid": "ai_bot_001",
"data": {
"type": 10101,
"robotid": "ai_bot_001",
"sender": "tts_bot_001",
"payload": {
"text": "Hello,can I help you?",
"end": false,
"roundid": "D7E2053C-6E1F-4941-9761-FEE0407016EF",
"taskid": "task-id"
}
}
}
Field
Type
Description
event
String
Fixed value: llmSubtitle.
robotid
String
UserId of the connected AI bot.
data.type
Number
Message type; LLM subtitle is 10101.
data.robotid
String
UserId of the AI conversation bot.
data.sender
String
UserId of the corresponding TTS bot.
data.payload.text
String
Full reply text for the current round so far.
data.payload.end
Boolean
false indicates an interim result; true indicates the round's reply is complete.
data.payload.roundid
String
Conversation round ID; matches the ASR subtitle that triggered this reply.
data.payload.taskid
String
AI conversation task ID.