Recorder

class Recorder

High-level wrapper around AudioRecordingSession providing a simplified API.

Example Usage

val recorder = Kodio.recorder()

recorder.start()
// Recording in progress...

// Stop and get result
recorder.stop()
val recording = recorder.getRecording()

// Clean up
recorder.release()

// Or use with structured concurrency
Kodio.record { recorder ->
recorder.start()
delay(5.seconds)
recorder.stop()
recorder.getRecording()
} // auto-released

Properties

Link copied to clipboard

The raw AudioFlow for advanced use cases.

Link copied to clipboard

The audio format of this recorder. Before recording starts, returns the requested format from quality. After recording starts, returns the actual negotiated format from the session (which may differ if the platform couldn't honor the exact request).

Link copied to clipboard

Whether the recorder is in stopped state with a recording available.

Link copied to clipboard

Whether the recorder is paused.

Link copied to clipboard

Whether the recorder is currently recording.

Link copied to clipboard

The live audio data as a Flow of byte arrays. This emits chunks in real-time while recording.

Link copied to clipboard

The requested audio quality

Link copied to clipboard

The current unified state of the recorder.

Link copied to clipboard

Flow of state changes for observing the recorder.

Functions

Link copied to clipboard
suspend fun awaitComplete()

Waits for the recording to complete (stop being called externally or error).

Link copied to clipboard

Gets the completed recording, if available.

Link copied to clipboard
suspend fun pause()

Pauses recording without losing the audio captured so far.

Link copied to clipboard
fun release()

Releases resources associated with this recorder. The recorder should not be used after calling this method.

Link copied to clipboard
fun reset()

Resets the recorder to idle state, discarding any recorded audio.

Link copied to clipboard
suspend fun resume()

Resumes a paused recording. No-op when the recorder is not currently in the paused state.

Link copied to clipboard
suspend fun start()

Starts recording audio.

Link copied to clipboard
fun stop()

Stops the current recording. After calling this, getRecording will return the recorded audio.

Link copied to clipboard
suspend fun toggle(): Boolean

Toggles recording on/off.

Link copied to clipboard

Access the underlying session for advanced use cases.

Link copied to clipboard
inline fun <T> Recorder.use(block: (Recorder) -> T): T

Extension for using Recorder with Kotlin's use pattern. Ensures proper cleanup even if an exception occurs.