Kodio 0.1.1 Help

Recording

Kodio provides two approaches to recording: a simple one-liner for timed recording, and a more flexible Recorder class for manual control.

Timed recording

The simplest way to record audio is with Kodio.record(). Pass a duration and Kodio handles the rest—starting, stopping, and packaging the audio into a recording.

val recording = Kodio.record(duration = 5.seconds)

You can also specify a quality preset to optimize for your use case:

val recording = Kodio.record( duration = 5.seconds, quality = AudioQuality.High // 48 kHz stereo )

Manual control

When you need to control when recording starts and stops (for example, based on user interaction), use the callback form of Kodio.record():

val recording = Kodio.record { recorder -> recorder.start() waitForUserStop() // Your app logic recorder.stop() recorder.getRecording() }

The lambda receives a Recorder instance and returns whatever the lambda returns—typically the recording itself.

Using Recorder directly

For maximum control, create a Recorder instance directly. This is useful when you need to:

  • Start and stop recording multiple times

  • Access live audio data

  • Manage the recorder's lifecycle explicitly

val recorder = Kodio.recorder(quality = AudioQuality.Standard) recorder.use { r -> r.start() delay(5.seconds) r.stop() r.getRecording()?.saveAs(Path("audio.wav")) }

The use extension ensures resources are properly released, even if an exception occurs.

Live audio processing

The Recorder provides a liveAudioFlow that emits audio chunks in real-time while recording. This is perfect for visualizations like waveforms or level meters.

recorder.liveAudioFlow?.collect { chunk -> val amplitude = calculateAmplitude(chunk) updateWaveform(amplitude) }

Recorder API reference

Properties

isRecording: Boolean

true while actively recording audio.

hasRecording: Boolean

true if a recording is available via getRecording().

quality: AudioQuality

The quality preset used for this recorder.

liveAudioFlow: Flow<ByteArray>?

Real-time audio data while recording. May be null on some platforms.

stateFlow: StateFlow<State>

Observable state changes for reactive UIs.

Methods

start()

Begin recording audio.

stop()

Stop recording. The recording becomes available via getRecording().

toggle()

Start if stopped, stop if recording. Convenient for single-button UIs.

reset()

Discard the current recording and prepare for a new one.

release()

Release all resources. Called automatically when using use {}.

getRecording(): AudioRecording?

Get the completed recording, or null if none available.

Last modified: 13 January 2026