Skip to content

Commit

Permalink
1. Fix auto start/stop transcription
Browse files Browse the repository at this point in the history
2. Show list of transcriptions
  • Loading branch information
rahul-lohra committed Dec 18, 2024
1 parent e82d637 commit 6a65116
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ import io.getstream.video.android.ui.menu.availableVideoFilters
import io.getstream.video.android.util.config.AppConfig
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import org.openapitools.client.models.OwnCapability
import org.openapitools.client.models.TranscriptionSettingsResponse

@OptIn(ExperimentalMaterialApi::class)
@Composable
Expand Down Expand Up @@ -173,6 +176,31 @@ fun CallScreen(
PaddingValues(0.dp)
}

/**
* AUTO START/STOP TRANSCRIPTION LOGIC
*
* This code handles the automatic transcription logic, ensuring transcription starts or stops
* based on the current settings and state. While it usually behaves as expected, consider the following scenario:
*
* - Transcription is set to "Auto-On" in the settings.
* - The current transcription state (`isCurrentlyTranscribing`) is `false` because it was toggled by a participant.
* - A new participant joins the call.
*
* In this scenario, the transcription will automatically start, overriding the previous `false` state.
* This behavior is intentional for this demo-app ONLY and designed to prioritize the "Auto-On" setting over the current state.
*
* Please keep this behavior in mind, as it might appear unexpected at first glance.
*/
val isCurrentlyTranscribing by call.state.transcribing.collectAsStateWithLifecycle()

LaunchedEffect(call.state.settings) {
call.state.settings.map { it?.transcription }
.distinctUntilChanged()
.collectLatest { transcription ->
executeTranscriptionApis(call, isCurrentlyTranscribing, transcription)
}
}

VideoTheme {
ChatDialog(
state = chatState,
Expand Down Expand Up @@ -595,6 +623,27 @@ fun CallScreen(
}
}

/**
* Executes the transcription APIs based on the current transcription state and settings.
*
* - Stops transcription if the mode is "Disabled" and transcription is currently active.
* - Starts transcription if the mode is "Auto-On" and transcription is not currently active.
* - Takes no action for other scenarios.
*/
private suspend fun executeTranscriptionApis(
call: Call,
transcribing: Boolean,
transcriptionSettingsResponse:
TranscriptionSettingsResponse?,
) {
val mode = transcriptionSettingsResponse?.mode
if (mode == TranscriptionSettingsResponse.Mode.Disabled && transcribing) {
call.stopTranscription()
} else if (mode == TranscriptionSettingsResponse.Mode.AutoOn && !transcribing) {
call.startTranscription()
} else { }
}

@Composable
private fun SpeakingWhileMuted() {
Snackbar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.os.Build
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.MobileScreenShare
import androidx.compose.material.icons.automirrored.filled.ReadMore
import androidx.compose.material.icons.automirrored.filled.ReceiptLong
import androidx.compose.material.icons.filled.AspectRatio
import androidx.compose.material.icons.filled.Audiotrack
import androidx.compose.material.icons.filled.AutoGraph
Expand Down Expand Up @@ -76,7 +77,7 @@ fun defaultStreamMenu(
loadRecordings: suspend () -> List<MenuItem>,
transcriptionUiState: TranscriptionUiState,
onToggleTranscription: suspend () -> Unit,
transcriptionList: suspend () -> List<MenuItem>,
loadTranscriptions: suspend () -> List<MenuItem>,
) = buildList<MenuItem> {
add(
DynamicSubMenuItem(
Expand Down Expand Up @@ -169,6 +170,14 @@ fun defaultStreamMenu(
},
),
)

add(
DynamicSubMenuItem(
title = "List Transcriptions",
icon = Icons.AutoMirrored.Filled.ReceiptLong,
itemsLoader = loadTranscriptions,
),
)
}

else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ internal fun SettingsMenu(
loadRecordings = onLoadRecordings,
transcriptionUiState = transcriptionUiState,
onToggleTranscription = onToggleTranscription,
transcriptionList = onLoadTranscriptions,
loadTranscriptions = onLoadTranscriptions,
),
)
}
Expand Down Expand Up @@ -352,7 +352,7 @@ private fun SettingsMenuPreview() {
loadRecordings = { emptyList() },
transcriptionUiState = TranscriptionAvailableUiState,
onToggleTranscription = {},
transcriptionList = { emptyList() },
loadTranscriptions = { emptyList() },
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private fun DynamicMenuPreview() {
loadRecordings = { emptyList() },
transcriptionUiState = TranscriptionAvailableUiState,
onToggleTranscription = {},
transcriptionList = { emptyList() },
loadTranscriptions = { emptyList() },
),
)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ private fun DynamicMenuDebugOptionPreview() {
loadRecordings = { emptyList() },
transcriptionUiState = TranscriptionAvailableUiState,
onToggleTranscription = {},
transcriptionList = { emptyList() },
loadTranscriptions = { emptyList() },
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ public class Call(
audioLevelOutputHelper.rampToValue(it)
}
}
observeTranscription()
}

/** Basic crud operations */
Expand Down

0 comments on commit 6a65116

Please sign in to comment.