SpeechToTextButton

fun SpeechToTextButton(state: SpeechToTextButtonState, modifier: Modifier = Modifier, onPermissionDenied: () -> Unit = { }, idleContent: @Composable (onClick: () -> Unit) -> Unit = { onClick -> with(LocalChatAiComponentFactory.current) { SpeechToTextButtonIdleContent(SpeechToTextButtonIdleContentParams(onClick = onClick)) } }, recordingContent: @Composable (onClick: () -> Unit, rmsdB: Float) -> Unit = { onClick, rmsdB -> with(LocalChatAiComponentFactory.current) { SpeechToTextButtonRecordingContent( SpeechToTextButtonRecordingContentParams(onClick = onClick, rmsdB = rmsdB), ) } })

A composable button that provides speech-to-text functionality.

When not recording, displays a microphone icon button. When recording, transforms into a circle with animated bars that respond to voice input.

The component automatically handles:

  • Audio permission requests

  • Starting and stopping speech recognition

  • Streaming recognized text chunks to the callback as they're detected

  • Animated visualization during recording

Parameters

state

The state holder for tracking recording status. Must be created with rememberSpeechToTextButtonState.

modifier

Modifier to be applied to the root container

onPermissionDenied

Callback invoked when microphone permission is denied.

idleContent

The composable content to display when not recording. Receives an onClick callback that toggles recording.

recordingContent

The composable content to display when recording. Receives an onClick callback that stops recording and the current audio level (rmsdB) for visualization.

See also