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

Link copied to clipboard

The most recent error, if any.

Link copied to clipboard

Whether there is an error.

Link copied to clipboard

Whether a recording is available.

Link copied to clipboard

Whether the recorder is busy (recording, paused, or processing).

Link copied to clipboard

Whether the recorder is paused (recording can be resumed via resume).

Link copied to clipboard

Whether the recorder is processing (e.g., collecting recorded data after stop).

Link copied to clipboard

Whether the recorder has been initialized successfully.

Link copied to clipboard

Whether the recorder is currently recording.

Link copied to clipboard

Live amplitude values for displaying a waveform. Updates in real-time while recording.

Link copied to clipboard

Whether permission is required before recording.

Link copied to clipboard

The current microphone permission state.

Link copied to clipboard

The completed recording, if available. This becomes non-null after stop is called and processing completes.

Functions

Link copied to clipboard

Clears the current error.

Link copied to clipboard
fun pause()

Pauses recording. The captured audio so far is preserved; call resume to continue appending to the same recording, or stop to finalize it.

Link copied to clipboard
suspend fun pauseAsync()

Suspend variant of pause.

Link copied to clipboard

Requests microphone permission.

Link copied to clipboard

Requests microphone permission (suspend version).

Link copied to clipboard
fun reset()

Resets the state, discarding any recording.

Link copied to clipboard
suspend fun resetAsync()

Resets the state, discarding any recording (suspend version).

Link copied to clipboard
fun resume()

Resumes a paused recording.

Link copied to clipboard
suspend fun resumeAsync()

Suspend variant of resume.

Link copied to clipboard
fun start()

Starts recording audio.

Link copied to clipboard
suspend fun startAsync()

Starts recording audio (suspend version).

Link copied to clipboard
fun stop()

Stops recording and makes the recording available. The recording will be available in recording once isProcessing becomes false.

Link copied to clipboard
suspend fun stopAsync(): AudioRecording?

Stops recording and waits for the recording to be ready (suspend version).

Link copied to clipboard
fun toggle()

Toggles recording on/off.

Link copied to clipboard
suspend fun toggleAsync(): Boolean

Toggles recording on/off (suspend version).