AudioRecording

Represents a recorded audio clip with its format metadata.

This is a higher-level abstraction over AudioFlow that provides convenient methods for common operations like saving to file and playback.

AudioRecording is immutable and thread-safe. All factory methods create defensive copies of input data to prevent external mutation.

Example Usage

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

// Save to file
recording.saveAs(Path("voice_note.wav"))

// Play it back
recording.play()

// Access raw data
val bytes = recording.toByteArray()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The calculated duration based on frame count and sample rate. Falls back to the provided duration if available.

Link copied to clipboard

The duration of the recording, if known

Link copied to clipboard

The audio format of this recording

Link copied to clipboard

The number of audio frames in this recording. A frame contains one sample per channel.

Link copied to clipboard

Whether this recording has audio data.

Link copied to clipboard

Whether this recording is empty (no audio data).

Link copied to clipboard

The total size of the audio data in bytes.

Functions

Link copied to clipboard

Returns the audio data as an AudioFlow for compatibility with existing APIs.

Link copied to clipboard
fun asFlow(defensiveCopy: Boolean = true): Flow<ByteArray>

Returns the audio data as a Flow of byte array chunks.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
suspend fun play()

Plays back this recording using the default audio output device. This is a convenience method that creates a playback session internally.

Link copied to clipboard
suspend fun saveAs(path: Path, fileFormat: AudioFileFormat = AudioFileFormat.Wav)

Saves the recording to a file in the specified format.

Link copied to clipboard

Collects all chunks into a single byte array. Note: This loads all audio data into memory. Returns a new array (not a reference to internal data).

Link copied to clipboard
open override fun toString(): String