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.
You can also specify a quality preset to optimize for your use case:
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():
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
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 API reference
Properties
- isRecording: Boolean
truewhile actively recording audio.- hasRecording: Boolean
trueif a recording is available viagetRecording().- quality: AudioQuality
The quality preset used for this recorder.
- liveAudioFlow: Flow<ByteArray>?
Real-time audio data while recording. May be
nullon 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
nullif none available.