Realtime Transcription - Android
Realtime transcription allows you to transcribe audio content into text in real-time during a session. This guide will walk you through using the startTranscription()
and stopTranscription()
functions to manage realtime transcription in your application.
Moreover, VideoSDK offers flexibility in configuring real-time transcription, allowing you to set up webhooks for this purpose.
Integrating Realtime Transcription Feature
The above image represents,
-
Start Transcription: The SDK Client initiates real-time transcription using the
startTranscription
method. -
Resource Acquisition: VideoSDK server requests necessary resources from transcription service.
- If the request is denied, the server sends a
transcription-failed
event to the SDK Client. - If the request is successful, the server sends a
onTranscriptionStateChanged
event with statusTRANSCRIPTION_STARTED
to the client, indicating that transcription has begun.
- If the request is denied, the server sends a
-
Transcription Data: As transcription progresses, the client receives
onTranscriptionText
event with data such as the text itself, participant ID, and timestamp. -
Stop Transcription: When the client decides to stop transcription, it informs the VideoSDK server to release resources.
- The server then sends a
onTranscriptionStateChanged
event with statusTRANSCRIPTION_STOPPED
to confirm that transcription has ended and resources are released.
- The server then sends a
Step 1: Configure Realtime Transcription
- In this step, we set up the configuration for realtime transcription. We define the webhook URL where the webhooks will be received.
- Kotlin
- Java
// Webhook URL where, webhooks are received
val webhookUrl = "YOUR_WEBHOOK_URL"
// Realtime Transcription Configuration
val summaryConfig = SummaryConfig(
true,
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary"
)
val transcription = TranscriptionConfig(
webhookUrl,
summaryConfig
)
// Webhook URL where, webhooks are received
final String webhookUrl = "YOUR_WEBHOOK_URL";
// Realtime Transcription Configuration
SummaryConfig summaryConfig = new SummaryConfig(
true,
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary"
);
TranscriptionConfig transcription = new TranscriptionConfig(
webhookUrl,
summaryConfig
);
Step 2: Listen for the transcription events
- Here, we configure the callback methods for transcription events.
- Kotlin
- Java
private val meetingEventListener: MeetingEventListener = object : MeetingEventListener() {
override fun onTranscriptionStateChanged(data: JSONObject) {
try {
val status = data.getString("status")
val id = data.getString("id")
when (status) {
TranscriptionState.TRANSCRIPTION_STARTING.name -> Log.d("onTranscriptionStateChanged", "Realtime Transcription is starting, ID: $id")
TranscriptionState.TRANSCRIPTION_STARTED.name -> Log.d("onTranscriptionStateChanged", "Realtime Transcription is started, ID: $id")
TranscriptionState.TRANSCRIPTION_STOPPING.name -> Log.d("onTranscriptionStateChanged", "Realtime Transcription is stopping, ID: $id")
TranscriptionState.TRANSCRIPTION_STOPPED.name -> Log.d("onTranscriptionStateChanged", "Realtime Transcription is stopped, ID: $id")
else -> Log.d("onTranscriptionStateChanged", "Unknown transcription state: $status, ID: $id")
}
} catch (e: JSONException) {
Log.e("onTranscriptionStateChanged", "Error parsing transcription state", e)
}
}
override fun onTranscriptionText(data: TranscriptionText) {
val participantId: String = data.participantId
val participantName: String = data.participantName
val text: String = data.text
val timestamp: Int = data.timestamp
val type: String = data.type
Log.d("onTranscriptionText", "$participantName: $text $timestamp")
}
}
override fun onCreate(savedInstanceState: Bundle?) {
//...
// add listener to meeting
meeting!!.addEventListener(meetingEventListener)
}
private final MeetingEventListener meetingEventListener = new MeetingEventListener() {
@Override
public void onTranscriptionStateChanged(JSONObject data) {
try {
String status = data.getString("status");
String id = data.getString("id");
if (TranscriptionState.TRANSCRIPTION_STARTING.name().equals(status)) {
Log.d("onTranscriptionStateChanged", "Realtime Transcription is starting, ID: " + id);
}
else if (TranscriptionState.TRANSCRIPTION_STARTED.name().equals(status)) {
Log.d("onTranscriptionStateChanged", "Realtime Transcription is started, ID: " + id);
}
else if (TranscriptionState.TRANSCRIPTION_STOPPING.name().equals(status)) {
Log.d("onTranscriptionStateChanged", "Realtime Transcription is stopping, ID: " + id);
}
else if (TranscriptionState.TRANSCRIPTION_STOPPED.name().equals(status)) {
Log.d("onTranscriptionStateChanged", "Realtime Transcription is stopped, ID: " + id);
}
else {
Log.d("onTranscriptionStateChanged", "Unknown transcription state: " + status + ", ID: " + id);
}
} catch (JSONException e) {
Log.e("onTranscriptionStateChanged", "Error parsing transcription state", e.getMessage());
}
}
@Override
public void onTranscriptionText(TranscriptionText data) {
String participantId = data.getParticipantId();
String participantName = data.getParticipantName();
String text = data.getText();
int timestamp = data.getTimestamp();
String type = data.getType();
Log.d("onTranscriptionText", participantName + ": " + text + " " + timestamp);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
// add listener to meeting
meeting.addEventListener(meetingEventListener);
}
Step 3: Start realtime transcription
- Initiate the realtime transcription using the
startTranscription()
method.
- Kotlin
- Java
fun startRealtimeTranscription() {
// Webhook URL where, webhooks are received
val webhookUrl = "YOUR_WEBHOOK_URL"
// Realtime Transcription Configuration
val summaryConfig = SummaryConfig(
true,
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary"
)
val transcription = TranscriptionConfig(
webhookUrl,
summaryConfig
)
meeting!!.startTranscription(transcription)
}
private void startRealtimeTranscription() {
// Webhook URL where, webhooks are received
final String webhookUrl = "YOUR_WEBHOOK_URL";
// Realtime Transcription Configuration
SummaryConfig summaryConfig = new SummaryConfig(
true,
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary"
);
TranscriptionConfig transcription = new TranscriptionConfig(
webhookUrl,
summaryConfig
);
meeting.startTranscription(transcription);
}
Step 4: Stop realtime transcription
- Terminate the realtime transcription using the
stopTranscription()
method.
- Kotlin
- Java
fun stopRealtimeTranscription() {
meeting!!.stopTranscription()
}
private void stopRealtimeTranscription() {
meeting.stopTranscription();
}
You can access a summary of your realtime transcription using the Fetch Realtime Transcription API.
Example
- The following code snippet allows you to start and stop realtime transcription with just a click. When you click the "Start Realtime Transcription" button, it begins realtime transcription. Clicking the "Stop Realtime Transcription" button ends the realtime transcription.
- Kotlin
- Java
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import org.json.JSONObject
class MeetingActivity : AppCompatActivity() {
private lateinit var meeting: Meeting
// add meetingEventListener to handle transcription events
private val meetingEventListener = object : MeetingEventListener {
override fun onTranscriptionStateChanged(data: JSONObject) {
val status = data.getString("status")
Log.d("MeetingActivity", "Transcription status: $status")
}
override fun onTranscriptionText(data: TranscriptionText) {
val participantId = data.participantId
val participantName = data.participantName
val text = data.text
val timestamp = data.timestamp
val type = data.type
Log.d("MeetingActivity", "$participantName: $text $timestamp")
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_meeting)
//initialize a meeting
//...
val startButton: Button = findViewById(R.id.startTranscriptionButton)
val stopButton: Button = findViewById(R.id.stopTranscriptionButton)
startButton.setOnClickListener { startRealtimeTranscription() }
stopButton.setOnClickListener { stopRealtimeTranscription() }
// add listener to meeting
meeting!!.setEventListener(meetingEventListener)
}
private fun startRealtimeTranscription() {
// Configuration for realtime transcription
val summaryConfig = SummaryConfig(
true,
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary"
)
val transcriptionConfig = TranscriptionConfig(
null,
summaryConfig
)
// Call to start transcription with the specified configuration
meeting!!.startTranscription(transcriptionConfig)
}
private fun stopRealtimeTranscription() {
// Call to stop transcription
meeting!!.stopTranscription()
}
}
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MeetingActivity extends AppCompatActivity {
private Meeting meeting;
// add meetingEventListener to handle transcription events
private final MeetingEventListener meetingEventListener = new MeetingEventListener() {
@Override
public void onTranscriptionStateChanged(JSONObject data) {
String status = data.getString("status");
Log.d("MeetingActivity", "Transcription status: " + status);
}
@Override
public void onTranscriptionText(TranscriptionText data) {
String participantId = data.getParticipantId();
String participantName = data.getParticipantName();
String text = data.getText();
int timestamp = data.getTimestamp();
String type = data.getType();
Log.d("MeetingActivity", participantName + ": " + text + " " + timestamp);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_meeting);
//initialize a meeting
//...
Button startButton = findViewById(R.id.startTranscriptionButton);
Button stopButton = findViewById(R.id.stopTranscriptionButton);
startButton.setOnClickListener(v -> startRealtimeTranscription());
stopButton.setOnClickListener(v -> stopRealtimeTranscription());
// add listener to meeting
meeting.setEventListener(meetingEventListener);
}
private void startRealtimeTranscription() {
// Configuration for realtime transcription
SummaryConfig summaryConfig = new SummaryConfig(
true,
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary"
);
TranscriptionConfig transcriptionConfig = new TranscriptionConfig(
null,
summaryConfig
);
// Call to start transcription with the specified configuration
meeting.startTranscription(transcriptionConfig);
}
private void stopRealtimeTranscription() {
// Call to stop transcription
meeting.stopTranscription();
}
}
API Reference
The API references for all the methods utilized in this guide are provided below.
Got a Question? Ask us on discord