This topic describes how to use AICallKit SDK to retrieve live subtitles for both user input and intelligent agent responses.
Overview
Live subtitles on the user side The user input is recognized by the intelligent agent and displayed on the UI in real time. 
| Live subtitles on the agent side The content generated by the large model is displayed on the UI in real time. 
|
How it works
During a call, the onUserSubtitleNotify
callback is triggered when the user's question is recognized by the intelligent agent. The onVoiceAgentSubtitleNotify
callback is triggered when the intelligent agent generates a response.
onUserSubtitleNotify details
While the user is talking, the agent's recognition result is returned multiple times via notifications. In live subtitle scenarios, the text content can be directly rendered and displayed on the UI. In conversational chat scenarios, the final text content is rendered and displayed on the UI when isSentenceEnd=true
is returned.
Parameter | Description |
text | The text recognized by the intelligent agent. |
isSentenceEnd | Indicates whether the current text is the end of the sentence. If this parameter is set to true, the intelligent agent starts answering the question. |
sentenceId | The ID of the sentence to which the current text belongs. The IDs are accumulated after each question is asked. |
voiceprintResult | The voiceprint recognition result. Valid values: 0: Voiceprint recognition is not enabled. 1: Voiceprint recognition is enabled but the speaker's voice is not registered. 2: Voiceprint recognition is enabled and the speaker is recognized. 3: Voiceprint recognition is enabled and the speaker is not recognized. In this case, the intelligent agent will not answer the question. Note AICallKit SDK for Web does not support voiceprint recognition. |
For example, when a user asks "What's the weather like today?", the following callback results may be returned:
text="What's the weather" isSentenceEnd=false sentenceId=1
text="like" isSentenceEnd=false sentenceId=1
text="today?" isSentenceEnd=true sentenceId=1
onVoiceAgentSubtitleNotify details
The intelligent agent's response is returned in multiple notifications. The client must merge these text fragments and render the combined text incrementally for display on the UI.
Parameter | Description |
text | The text of the answer provided by the intelligent agent. |
isSentenceEnd | Indicates whether the current text is the final sentence of the answer. If this parameter is set to true, the intelligent agent finishes answering the question and enters the Listening state. |
userAsrSentenceId | The ID of the sentence that the user's question recognized by the intelligent agent belongs to. |
For example, in response to the user's question, the agent replied, "Today's weather is clear and sunny, with a mild temperature, so it's a nice day to go outside." The following callback results may be returned:
text="Today's weather is clear and sunny," isSentenceEnd=false userAsrSentenceId=1
text="with a mild temperature, so it's a nice day to go outside." isSentenceEnd=false userAsrSentenceId=1
text="" isSentenceEnd=true userAsrSentenceId=1
Sample code
mARTCAICallEngine.setEngineCallback(mCallEngineCallbackWrapper);
ARTCAICallEngine.IARTCAICallEngineCallback mCallEngineCallbackWrapper = new ARTCAICallEngine.IARTCAICallEngineCallback() {
@Override
public void onUserAsrSubtitleNotify(String text, boolean isSentenceEnd, int sentenceId, VoicePrintStatusCode voicePrintStatusCode) {
}
@Override
public void onAIAgentSubtitleNotify(String text, boolean end, int userAsrSentenceId) {
}
}
self.engine.delegate = self
func onUserSubtitleNotify(text: String, isSentenceEnd: Bool, sentenceId: Int, voiceprintResult: ARTCAICallVoiceprintResult) {
}
func onVoiceAgentSubtitleNotify(text: String, isSentenceEnd: Bool, userAsrSentenceId: Int) {
}
engine.on('userSubtitleNotify', (subtitle) => {
console.log('AICallUserSubtitleNotify', subtitle.text, subtitle.end, subtitle.sentenceId);
});
engine.on('agentSubtitleNotify', (subtitle) => {
console.log('AICallAgentSubtitleNotify', subtitle.text, subtitle.end, subtitle.sentenceId);
});