Voice¶
Talking to the agent: voice mode, the persona, dictation and voice choices.
Voice mode¶
A hands-free conversation over the chat's controller.

| API | VoiceMode(controller, onClose) |
| Artifact | ai-elements-ui |
| Reference | VoiceMode |
Declare RECORD_AUDIO and let the permission flow complete. Requires installed recognition/TTS services. onClose should dismiss the hosting dialog or screen.
import androidx.compose.runtime.Composable
import dev.ai.elements.core.chat.ChatController
import dev.ai.elements.ui.voice.VoiceMode
@Composable
fun VoiceModeExample(controller: ChatController, onClose: () -> Unit) {
VoiceMode(controller, onClose = onClose)
}
Persona¶
The assistant's animated presence: idle, listening, thinking, speaking.

| API | Persona(state, size, level) |
| AI Elements | Persona |
| Artifact | ai-elements-ui |
| Reference | Persona |
Visual state only; this does not listen or speak. Feed level from your audio state when showing LISTENING or SPEAKING.
import androidx.compose.runtime.Composable
import dev.ai.elements.ui.voice.Persona
import dev.ai.elements.ui.voice.PersonaState
Speech input¶
Dictation with the platform speech recognizer.

| API | SpeechInput(onTranscript, state) |
| AI Elements | SpeechInput |
| Artifact | ai-elements-ui |
| Reference | SpeechInput |
Declare RECORD_AUDIO. State owns the recognizer lifecycle; show speech.error on failure and distinguish interim/final transcripts in onTranscript.
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import dev.ai.elements.ui.voice.SpeechInput
import dev.ai.elements.ui.voice.rememberSpeechInputState
@Composable
fun SpeechInputExample() {
val speech = rememberSpeechInputState()
var transcript by rememberSaveable { mutableStateOf("") }
Column { SpeechInput(onTranscript = { text, _ -> transcript = text }, state = speech); Text(transcript) }
}
Mic & voice selectors¶
Choose the microphone and the reading voice.

| API | MicSelector(selected, onSelect), VoiceSelector(voices, selectedId, onSelect) |
| AI Elements | MicSelector, VoiceSelector |
| Artifact | ai-elements-ui |
| Reference | MicSelector |
Selectors report choices; configure your audio engine or SpeechSettings separately. Available microphones and voices depend on the device.
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import dev.ai.elements.ui.voice.MicSelector
import dev.ai.elements.ui.voice.VoiceOption
import dev.ai.elements.ui.voice.VoiceSelector
@Composable
fun VoiceSelectorsExample() {
var mic by remember { mutableStateOf<android.media.AudioDeviceInfo?>(null) }
var voice by rememberSaveable { mutableStateOf("default") }
Column {
MicSelector(mic, onSelect = { mic = it })
VoiceSelector(listOf(VoiceOption("default", "Default")), voice, onSelect = { voice = it.id })
}
}