RecorderState
State holder for audio recording in Compose.
Provides a simplified, reactive API for recording audio that integrates with Compose's state management.
Example Usage
@Composable
fun VoiceRecorder() {
val recorderState = rememberRecorderState()
Column {
// Show recording status
Text(
when {
recorderState.isRecording -> "Recording..."
recorderState.isProcessing -> "Processing..."
else -> "Ready"
}
)
// Record button
Button(
onClick = { recorderState.toggle() },
enabled = !recorderState.isProcessing
) {
Text(if (recorderState.isRecording) "Stop" else "Record")
}
// Show waveform while recording
if (recorderState.isRecording) {
AudioWaveform(amplitudes = recorderState.liveAmplitudes)
}
// Access the recording when done
recorderState.recording?.let { recording ->
Button(onClick = { recording.play() }) {
Text("Play Recording")
}
}
}
}Properties
The most recent error, if any.
Whether a recording is available.
Whether the recorder is processing (e.g., collecting recorded data after stop).
Whether the recorder is currently recording.
Live amplitude values for displaying a waveform. Updates in real-time while recording.
Whether permission is required before recording.
The current microphone permission state.
The completed recording, if available. This becomes non-null after stop is called and processing completes.
Functions
Clears the current error.
Suspend variant of pause.
Requests microphone permission.
Requests microphone permission (suspend version).
Resets the state, discarding any recording (suspend version).
Suspend variant of resume.
Starts recording audio (suspend version).
Stops recording and makes the recording available. The recording will be available in recording once isProcessing becomes false.
Stops recording and waits for the recording to be ready (suspend version).
Toggles recording on/off (suspend version).