Skip to main content
Version: 0.x.x

Live Captioning for Livestreams - Android

Live captioning enhances your livestreams by converting hosts' speech into text in real-time, boosting accessibility and engagement. Using the startTranscription() and stopTranscription() methods, you can enable or disable captions on the fly, and display captions dynamically in your UI for all viewers.

Video SDK offers flexible configuration and event-driven updates to help you integrate captions seamlessly into your broadcast layout.

startTranscription()​

The startTranscription() method, accesible from the Meeting class, is used to initiate live captions in a live stream.

stopTranscription()​

The stopTranscription() method, accesible from the Meeting class, is used to stop the live captions in a live stream.

Example​

import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import live.videosdk.rtc.android.Meeting
import live.videosdk.rtc.android.VideoSDK
import live.videosdk.rtc.android.meeting.SummaryConfig
import live.videosdk.rtc.android.meeting.TranscriptionConfig

class LiveStreamActivity : AppCompatActivity() {

private lateinit var liveStream: Meeting

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_live_stream)

// Initialize the meeting (replace with actual meeting ID and token)
liveStream = VideoSDK.initMeeting(... )

val startCaptionsButton: Button = findViewById(R.id.btn_start_captions)
val stopCaptionsButton: Button = findViewById(R.id.btn_stop_captions)

startCaptionsButton.setOnClickListener {
startRealtimeTranscription()
}

stopCaptionsButton.setOnClickListener {
stopRealtimeTranscription()
}
}

private fun startRealtimeTranscription() {
val webhookUrl = "https://www.example.com"

val summaryConfig = SummaryConfig(
true,
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary"
)

val transcriptionConfig = TranscriptionConfig(
webhookUrl,
summaryConfig
)

liveStream.startTranscription(transcriptionConfig)
}

private fun stopRealtimeTranscription() {
liveStream.stopTranscription()
}
}

Events associated with live captioning​

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
liveStream!!.addEventListener(meetingEventListener)
}

API Reference​

The API references for all the methods utilized in this guide are provided below.

Got a Question? Ask us on discord