Package-level declarations

Types

Link copied to clipboard
@Stable
class AudioPlayerState

Playback state for AudioPlayer, hoisted so other elements can follow it (e.g. Transcription highlighting the segment being played).

Link copied to clipboard

What a voice agent is doing; drives Persona's animation.

Link copied to clipboard
data class RecognitionServiceInfo(val component: ComponentName, val label: String)

An installed speech recognition service.

Link copied to clipboard
Link copied to clipboard
@Stable
class SpeechInputState

On-device speech recognition state (Android SpeechRecognizer), exposed so a UI can show the live level (e.g. on a Persona).

Link copied to clipboard
@Stable
class SpeechOutputState

Speech output on the platform text-to-speech engine (Android TextToSpeech): reads a message aloud, or a reply sentence by sentence while it streams (enqueue). One utterance group is active at a time, named by speakingId; stop ends it.

Link copied to clipboard
@Immutable
data class SpeechSettings(val recognizer: ComponentName? = null, val onDeviceRecognition: Boolean = false, val ttsEngine: String? = null, val voice: String? = null, val rate: Float = 1.0f, val pitch: Float = 1.0f)

Which of the device's speech engines the voice elements use, and how they speak. Every field defaults to the system's choice, so an app only sets what its user picked (e.g. from recognitionServices and SpeechOutputState.engines in a settings screen).

Link copied to clipboard
@Immutable
data class TranscriptSegment(val text: String, val startMs: Long, val endMs: Long, val speaker: String? = null)

A timed piece of a transcript.

Link copied to clipboard
@Immutable
data class VoiceOption(val id: String, val name: String, val description: String? = null, val language: String? = null, val previewUrl: String? = null)

A text-to-speech voice in VoiceSelector.

Link copied to clipboard

Where a VoiceMode conversation is.

Properties

Link copied to clipboard
val LocalSpeechOutput: ProvidableCompositionLocal<SpeechOutputState?>

The speech output the elements use: the messages' "Read aloud" and VoiceMode. dev.ai.elements.ui.chat.Conversation creates one when none is provided; provide your own to share one engine across screens.

Link copied to clipboard
val LocalSpeechSettings: ProvidableCompositionLocal<SpeechSettings>

The speech engines the voice elements (SpeechInput, "Read aloud", VoiceMode) use.

Functions

Link copied to clipboard
@Composable
fun AudioPlayer(state: AudioPlayerState, modifier: Modifier = Modifier, title: String? = null)

An audio player for generated speech and recordings (AI Elements <AudioPlayer>): play / pause, ±10 s, a seek bar with times, and speed.

Link copied to clipboard

Whether on-device recognition (SpeechSettings.onDeviceRecognition) is offered here.

Link copied to clipboard
@Composable
fun MicSelector(selected: AudioDeviceInfo?, onSelect: (AudioDeviceInfo?) -> Unit, modifier: Modifier = Modifier)

Pick the microphone (AI Elements <MicSelector>): lists the system's input devices — built-in, wired, Bluetooth, USB — and updates as they are plugged in. null means the system default. Apply the choice with e.g. AudioRecord.setPreferredDevice.

Link copied to clipboard
@Composable
fun Persona(state: PersonaState, modifier: Modifier = Modifier, size: Dp = 96.dp, level: () -> Float = { 0f })

An animated agent presence for voice UIs (AI Elements <Persona>), drawn with Material 3 Expressive shapes instead of a Rive file: it breathes when idle, ripples while listening, morphs through shapes while thinking, pulses with level (0–1, e.g. output loudness) while speaking, and dims asleep. State changes morph from the previous shape.

Link copied to clipboard

The speech recognition services installed on the device (needs the <queries> ai-elements-ui declares).

Link copied to clipboard

Remembers an AudioPlayerState for source (URL, content:// URI or file path), released with the composition.

Link copied to clipboard
@Composable
fun rememberSpeechInputState(settings: SpeechSettings = LocalSpeechSettings.current): SpeechInputState

Remembers a SpeechInputState on the recognizer of settings; released with the composition.

Link copied to clipboard
@Composable
fun rememberSpeechOutputState(settings: SpeechSettings = LocalSpeechSettings.current): SpeechOutputState

Remembers a SpeechOutputState on the engine and voice of settings; released with the composition.

Link copied to clipboard
fun speakableText(markdown: String): String

markdown as text to read aloud: code blocks, diagrams and math are left out (they are not speakable), links read as their text, and Markdown markers are removed.

Link copied to clipboard
@Composable
fun SpeechInput(onTranscript: (text: String, isFinal: Boolean) -> Unit, modifier: Modifier = Modifier, state: SpeechInputState = rememberSpeechInputState(), locale: Locale? = null, onCancel: () -> Unit? = null)

Voice input (AI Elements <SpeechInput>): tap to dictate, tap again to stop. onTranscript receives partial text while speaking and the final text (isFinal = true) at the end. With onCancel, dictation shows the input level with cancel (drop what was heard; restore your text in onCancel) and done. Asks for the microphone permission the first time; the host app must declare RECORD_AUDIO in its manifest.

Link copied to clipboard
@Composable
fun Transcription(segments: List<TranscriptSegment>, modifier: Modifier = Modifier, currentTimeMs: Long = -1, onSeek: (Long) -> Unit? = null)

A transcript that follows playback (AI Elements <Transcription>): the segment at currentTimeMs is highlighted, what's already been said stays full-strength, what's ahead is dimmed, and tapping a segment calls onSeek with its start. Consecutive segments from the same TranscriptSegment.speaker form one paragraph.

Link copied to clipboard
@Composable
fun VoiceMode(controller: ChatController, onClose: () -> Unit, modifier: Modifier = Modifier, locale: Locale? = null, speech: SpeechOutputState = LocalSpeechOutput.current ?: rememberSpeechOutputState(), listening: SpeechInputState = rememberSpeechInputState())

A hands-free voice conversation over any chat, like the assistant apps' voice mode: it listens (platform speech recognition), sends what the user said to controller, reads the reply aloud sentence by sentence while it streams (platform text-to-speech), then listens again.

Link copied to clipboard
@Composable
fun VoiceSelector(voices: List<VoiceOption>, selectedId: String?, onSelect: (VoiceOption) -> Unit, modifier: Modifier = Modifier)

Pick a text-to-speech voice (AI Elements <VoiceSelector>): a chip opens a searchable sheet; voices with a VoiceOption.previewUrl can be heard before choosing.