Display live transcripts
Updated
Add real-time transcripts to your conversations with the Conversational AI agent.
When interacting with conversational AI in real time, you can enable live transcripts to display the conversation content. This page explains how to implement live transcripts in your app.
Understand the tech
Agora provides a flexible, scalable, and standardized conversational AI engine toolkit. The toolkit supports iOS, Android, and Web platforms, and encapsulates scenario-based APIs. You can use these APIs to integrate the capabilities of the Agora Signaling SDK and Agora Video SDK to enable the following features:
- Interrupt agents
- Display live transcripts
- Client-side events
- Set optimal audio parameters for iOS and Android
- Send picture messages
The toolkit receives transcript content through the onTranscriptUpdated callback and supports monitoring the following transcript data types:
- Agent transcript: The agent's speech, including streaming updates and final results.
- User transcript: The user's speech, including real-time display and status management.
- Transcript status: State changes such as in progress, completed, or interrupted.
The following diagram outlines the step-by-step process to integrate live transcript functionality into your application:
Transcript rendering workflow
Prerequisites
Before you begin, ensure the following:
- You have implemented the Conversational AI Engine quickstart.
- Your app integrates Agora Video SDK v4.5.1 or later and includes the Video SDK quickstart.
- You have enabled Signaling in the Agora Console and completed the Signaling quickstart for basic messaging.
- You maintain active and authenticated RTC and Signaling instances that persist beyond the component lifecycle. The toolkit does not manage RTC or Signaling initialization, lifecycle, or authentication.
Implementation
This section describes how to receive transcript content from the transcript processing module and display it in your app UI.
-
Integrate the toolkit
Copy the
convoaiApifolder to your project and import the toolkit before calling the toolkit API. Refer to Folder structure to understand the role of each file. -
Create a toolkit instance
Create a configuration object with the Video SDK and Signaling engine instances. Set the transcript rendering mode, then use the configuration to create a toolkit instance.
// Create configuration objects for the RTC and RTM instances val config = ConversationalAIAPIConfig( rtcEngine = rtcEngineInstance, rtmClient = rtmClientInstance, // Set the transcript rendering mode. Options: // - TranscriptRenderMode.Word: render transcript word by word. // - TranscriptRenderMode.Text: render the full sentence at once. renderMode = TranscriptRenderMode.Word, enableLog = true ) // Create component instance val api = ConversationalAIAPIImpl(config) -
Subscribe to the channel
Transcript data is delivered through Signaling channel messages. To receive transcript data, call
subscribeMessagebefore starting the agent session.api.subscribeMessage("channelName") { error -> if (error != null) { // Handle error } } -
Receive transcript
Call the
addHandlermethod to register your implementation of the transcription callback.api.addHandler(covEventHandler) -
Implement UI rendering logic
Inherit your UI module from the
IConversationalAIAPIEventHandlerinterface. Implement theonTranscriptUpdatedmethod to handle transcript rendering to the UI.private val covEventHandler = object : IConversationalAIAPIEventHandler { override fun onTranscriptUpdated(agentUserId: String, transcript: Transcript) { // Handle transcript data and update the UI here } } -
Add a conversational AI agent to the channel
To start a conversational AI agent, configure the following parameters in your
POSTrequest:Parameter Description Required advanced_features.enable_rtm: trueStarts the Signaling service Yes parameters.data_channel: "rtm"Enables Signaling as the data transmission channel Yes parameters.enable_metrics: trueEnables agent performance data collection Optional parameters.enable_error_message: trueEnables reporting of agent error events Optional After a successful response, the agent joins the specified RTC channel and is ready to interact with the user.
-
Unsubscribe from the channel
After an agent session ends, unsubscribe from channel messages to release transcription resources.
api.unsubscribeMessage("channelName") { error -> if (error != null) { // Handle the error } } -
Release resources
At the end of each call, use the
destroymethod to clean up the cache.api.destroy()
-
Integrate the toolkit
Copy the
ConversationalAIAPIfolder to your project and import the toolkit before calling the toolkit APIs. Refer to Folder structure to understand the role of each file. -
Create a toolkit instance
Create a configuration object with the Video SDK and Signaling engine instances. Set the transcript rendering mode, then use the configuration to create a toolkit instance.
// Create a configuration object for the RTC and RTM instances let config = ConversationalAIAPIConfig( rtcEngine: rtcEngine, rtmEngine: rtmEngine, /** * Set the transcript rendering mode. Available options: * - .words: Word-by-word rendering mode. * - .text: Sentence-by-sentence rendering mode. */ renderMode: .words, enableLog: true ) // Create the component instance convoAIAPI = ConversationalAIAPIImpl(config: config) -
Subscribe to the channel
Transcript data is delivered through Signaling channel messages. To receive transcript data, call
subscribeMessagebefore starting the agent session.convoAIAPI.subscribeMessage(channelName: channelName) { error in if let error = error { print("Subscription failed: \(error.message)") } else { print("Subscription successful") } } -
Receive transcript
Call the
addHandlermethod to register and implement the transcript callback.convoAIAPI.addHandler(handler: self) -
Implement UI rendering logic
Implement the
ConversationalAIAPIEventHandlerprotocol in your UI module, and useonTranscriptUpdatedto handle and render transcript updates.extension ChatViewController: ConversationalAIAPIEventHandler { public func onTranscriptUpdated(agentUserId: String, transcript: Transcript) { // Handle transcript data and update the UI here } } -
Add a conversational AI agent to the channel
To start a conversational AI agent, configure the following parameters in your
POSTrequest:Parameter Description Required advanced_features.enable_rtm: trueStarts the Signaling service Yes parameters.data_channel: "rtm"Enables Signaling as the data transmission channel Yes parameters.enable_metrics: trueEnables agent performance data collection Optional parameters.enable_error_message: trueEnables reporting of agent error events Optional After a successful response, the agent joins the specified RTC channel and is ready to interact with the user.
-
Unsubscribe from the channel
After each agent session ends, unsubscribe from channel messages to release transcript-related resources.
convoAIAPI.unsubscribeMessage(channelName: channelName) { error in if let error = error { print("Unsubscription failed: \(error.message)") } else { print("Unsubscribed successfully") } } -
Release resources
At the end of each call, use the
destroymethod to clean up the cache.convoAIAPI.destroy()
-
Integrate the toolkit
Copy the
conversational-ai-apifile to your project and import the toolkit before calling its APIs. Refer to Folder structure to understand the role of each file. -
Create a toolkit instance
Before joining an RTC channel, create Video SDK and Signaling engine instances and pass them into the toolkit instance.
// Initialize the component ConversationalAIAPI.init({ rtcEngine, rtmEngine, /** * Set the rendering mode for transcript. Available options: * - ESubtitleHelperMode.WORD: render transcript word by word. * - ESubtitleHelperMode.TEXT: render the full transcript at once. */ renderMode: ESubtitleHelperMode.WORD, }) // Get the API instance (singleton) const conversationalAIAPI = ConversationalAIAPI.getInstance() -
Set audio parameters
In word-by-word rendering mode, you must receive audio timestamp metadata from RTC to synchronize subtitles with speech. Before creating the client object, configure the following parameter:
AgoraRTC.setParameter('ENABLE_AUDIO_PTS_METADATA', true) const client = AgoraRTC.createClient({ mode: 'rtc', codec: 'vp8' }) -
Subscribe to the channel
Agent-related events are delivered through Signaling messages. Before starting an agent session, call
subscribeMessageto receive these events:conversationalAIAPI.subscribeMessage(channel_name) -
Receive transcript
Register an event listener to receive transcript updates:
import * as React from 'react' import { type IUserTranscription, type IAgentTranscription, type ISubtitleHelperItem, EConversationalAIAPIEvents, } from '@/conversational-ai-api/type' import { ConversationalAIAPI } from '@/conversational-ai-api' export const ChatHistory = () => { const [chatHistory, setChatHistory] = React.useState< ISubtitleHelperItem<Partial<IUserTranscription | IAgentTranscription>>[] >([]) const conversationalAIAPI = ConversationalAIAPI.getInstance() conversationalAIAPI.on( EConversationalAIAPIEvents.TRANSCRIPT_UPDATED, setChatHistory ) return ( <> {chatHistory.map((message) => ( <div key={`${message.uid}-${message.turn_id}`}> {message.uid}: {message.text} </div> ))} </> ) } -
Add a conversational AI agent to the channel
To start a conversational AI agent, configure the following parameters in your
POSTrequest:Parameter Description Required advanced_features.enable_rtm: trueStarts the Signaling service Yes parameters.data_channel: "rtm"Enables Signaling as the data transmission channel Yes parameters.enable_metrics: trueEnables agent performance data collection Optional parameters.enable_error_message: trueEnables reporting of agent error events Optional After a successful response, the agent joins the specified RTC channel and is ready to interact with the user.
-
Unsubscribe from the channel
After each agent session ends, unsubscribe from channel messages to release resources associated with callback events.
conversationalAIAPI.unsubscribeMessage(channel_name) -
Release resources
At the end of each call, use the
destroymethod to clean up the cache.conversationalAIAPI.destroy()
Reference
This section contains supporting information that completes the guidance on this page.
Folder structure
IConversationalAIAPI.kt: API interface and related data structures and enumerationsConversationalAIAPIImpl.kt: ConversationalAI API main implementation logicConversationalAIUtils.kt: tool functions and event callback managementsubRender/v3/: transcription moduleTranscriptionController.kt: transcription controllerMessageParser.kt: message parser
API reference
Folder structure
ConversationalAIAPI.swift: API interface and related data structures and enumerationsConversationalAIAPIImpl.swift: ConversationalAI API main implementation logicTranscription/TranscriptionController.swift: transcription controller
API reference
Folder structure
index.ts: API classtype.ts: API interface and related data structures and enumerationsutils/index.ts: API utility functionsevents.ts: event management classsub-render.ts: transcription module
API reference
