Quick Start
This page provides ready-to-use code snippets for the most common Kodio use cases. For detailed explanations, see the dedicated pages for Recording and Playback.
Record for a fixed duration
Record audio for exactly 5 seconds and get the result:
val recording = Kodio.record(
duration = 5.seconds,
quality = AudioQuality.Voice
)
Record until stopped
Start recording and wait for the user (or your app logic) to stop it:
val recording = Kodio.record { recorder ->
recorder.start()
// ... wait for user action ...
recorder.stop()
recorder.getRecording()
}
Record with automatic cleanup
Use Kotlin's use extension to ensure resources are released even if something goes wrong:
Kodio.recorder().use { recorder ->
recorder.start()
delay(5.seconds)
recorder.stop()
recorder.getRecording()?.saveAs(Path("audio.wav"))
}
Play a recording
One line to play audio and wait for completion:
recording.play()
Get access to pause, resume, and other controls:
Kodio.play(recording) { player ->
player.start()
delay(2.seconds)
player.pause()
delay(1.seconds)
player.resume()
player.awaitComplete()
}
Save to file
Save a recording as a WAV file:
recording.saveAs(Path("my-recording.wav"))
Compose UI
Build a recording UI with just a few lines:
@Composable
fun VoiceRecorder() {
val recorderState = rememberRecorderState()
Column {
// Show waveform while recording
if (recorderState.isRecording) {
AudioWaveform(
amplitudes = recorderState.liveAmplitudes,
modifier = Modifier.fillMaxWidth().height(64.dp)
)
}
// Record button
Button(onClick = { recorderState.toggle() }) {
Text(if (recorderState.isRecording) "⏹ Stop" else "🎙 Record")
}
}
}
Quality presets reference
Choose the right quality for your use case:
Preset | Sample Rate | Channels | Best for |
|---|
🎤 Voice | 16 kHz | Mono | Speech, voice memos |
🎵 Standard | 44.1 kHz | Mono | General audio |
🎧 High | 48 kHz | Stereo | Music, podcasts |
🎚️ Lossless | 96 kHz | Stereo, 24-bit | Studio recording |
Kodio.record(duration = 5.seconds, quality = AudioQuality.Voice)
Kodio.record(duration = 5.seconds, quality = AudioQuality.High)
Last modified: 13 January 2026