Unlock the Power of AI

1 million free tokens

88% Price Reduction

NaNDayNaN:NaN:NaN
Activate Now

Live subtitles

Updated at: 2025-03-14 02:11

This topic describes how to use AICallKit SDK to retrieve live subtitles for both user input and intelligent agent responses.

Usage notes

Overview

Live subtitles on the user side

The user input is recognized by the intelligent agent and displayed on the UI in real time.

lQDPKeLM6OXzFGHNCMjNBDiwmvXWuI7zQ84HVy-x3Np4AA_1080_2248

Live subtitles on the agent side

The content generated by the large model is displayed on the UI in real time.

lQDPJyB9LXbMhGHNCMjNBDiw5kh8C3S6jikHVy-y6E6YAA_1080_2248

Note

This feature is included in the integration solution with a UI.

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

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

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

Android
iOS
Web
// Register a callback for a call engine.
mARTCAICallEngine.setEngineCallback(mCallEngineCallbackWrapper); 

// Handle callback events.
ARTCAICallEngine.IARTCAICallEngineCallback mCallEngineCallbackWrapper = new ARTCAICallEngine.IARTCAICallEngineCallback() {
    @Override
    public void onUserAsrSubtitleNotify(String text, boolean isSentenceEnd, int sentenceId, VoicePrintStatusCode voicePrintStatusCode) {
        // Synchronize the ASR-recognized text.
    }

    @Override
    public void onAIAgentSubtitleNotify(String text, boolean end, int userAsrSentenceId) {
        // Synchronize the response of the intelligent agent.
    }
}
// Register a callback for a call engine.
self.engine.delegate = self

func onUserSubtitleNotify(text: String, isSentenceEnd: Bool, sentenceId: Int, voiceprintResult: ARTCAICallVoiceprintResult) {
    // Triggered when the user's question is recognized by the intelligent agent.
}

func onVoiceAgentSubtitleNotify(text: String, isSentenceEnd: Bool, userAsrSentenceId: Int) {
    // Triggered when the intelligent agent generates a response.
}
// Register a callback for a call engine.
engine.on('userSubtitleNotify', (subtitle) => {
  // Triggered when the user's question is recognized by the intelligent agent.
  console.log('AICallUserSubtitleNotify', subtitle.text, subtitle.end, subtitle.sentenceId);
});
engine.on('agentSubtitleNotify', (subtitle) => {
  // Triggered when the intelligent agent generates a response.
  console.log('AICallAgentSubtitleNotify', subtitle.text, subtitle.end, subtitle.sentenceId);
});
  • On this page (1, T)
  • Usage notes
  • Overview
  • How it works
  • onUserSubtitleNotify details
  • onVoiceAgentSubtitleNotify details
  • Sample code
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare