AudioFileReader

actual class AudioFileReader(filePath: String)

Reads and decodes audio data from a file on disk or a remote URL.

The reader decodes compressed formats (MP3, AAC, M4A) into PCM float samples normalized to the range [-1.0, 1.0]. Samples are interleaved when the file contains multiple channels (left, right, left, right, ...).

Supported formats

Threading

A single AudioFileReader instance is not thread-safe. Do not call readAll, readFrames, or seekTo concurrently from multiple threads. If you need to read the same file from multiple threads, create a separate reader per thread.

Usage

// Read an entire file at once
val reader = AudioFileReader("/path/to/audio.wav")
val info = reader.info
println("Duration: ${info.durationMs} ms, Channels: ${info.channelCount}")
val samples = reader.readAll()
reader.close()

// Stream in chunks (useful for large files)
val reader2 = AudioFileReader("https://example.com/audio.m4a")
while (!reader2.isAtEnd) {
val chunk = reader2.readFrames(4096)
// process chunk ...
}
reader2.close()

Always call close when finished to release native resources.

Parameters

filePath

Absolute path to a local file, or an HTTP/HTTPS URL. On JS the path must already be in the in-memory store (decodeAudioFile, putWavBytes, putAudioFile, or a previous AudioFileWriter).

See also

Throws

if the file cannot be opened or the format is not recognized.

actual class AudioFileReader(filePath: String)

Reads and decodes audio data from a file on disk or a remote URL.

The reader decodes compressed formats (MP3, AAC, M4A) into PCM float samples normalized to the range [-1.0, 1.0]. Samples are interleaved when the file contains multiple channels (left, right, left, right, ...).

Supported formats

Threading

A single AudioFileReader instance is not thread-safe. Do not call readAll, readFrames, or seekTo concurrently from multiple threads. If you need to read the same file from multiple threads, create a separate reader per thread.

Usage

// Read an entire file at once
val reader = AudioFileReader("/path/to/audio.wav")
val info = reader.info
println("Duration: ${info.durationMs} ms, Channels: ${info.channelCount}")
val samples = reader.readAll()
reader.close()

// Stream in chunks (useful for large files)
val reader2 = AudioFileReader("https://example.com/audio.m4a")
while (!reader2.isAtEnd) {
val chunk = reader2.readFrames(4096)
// process chunk ...
}
reader2.close()

Always call close when finished to release native resources.

Parameters

filePath

Absolute path to a local file, or an HTTP/HTTPS URL. On JS the path must already be in the in-memory store (decodeAudioFile, putWavBytes, putAudioFile, or a previous AudioFileWriter).

See also

Throws

if the file cannot be opened or the format is not recognized.

expect class AudioFileReader(filePath: String)

Reads and decodes audio data from a file on disk or a remote URL.

The reader decodes compressed formats (MP3, AAC, M4A) into PCM float samples normalized to the range [-1.0, 1.0]. Samples are interleaved when the file contains multiple channels (left, right, left, right, ...).

Supported formats

Threading

A single AudioFileReader instance is not thread-safe. Do not call readAll, readFrames, or seekTo concurrently from multiple threads. If you need to read the same file from multiple threads, create a separate reader per thread.

Usage

// Read an entire file at once
val reader = AudioFileReader("/path/to/audio.wav")
val info = reader.info
println("Duration: ${info.durationMs} ms, Channels: ${info.channelCount}")
val samples = reader.readAll()
reader.close()

// Stream in chunks (useful for large files)
val reader2 = AudioFileReader("https://example.com/audio.m4a")
while (!reader2.isAtEnd) {
val chunk = reader2.readFrames(4096)
// process chunk ...
}
reader2.close()

Always call close when finished to release native resources.

Parameters

filePath

Absolute path to a local file, or an HTTP/HTTPS URL. On JS the path must already be in the in-memory store (decodeAudioFile, putWavBytes, putAudioFile, or a previous AudioFileWriter).

See also

Throws

if the file cannot be opened or the format is not recognized.

actual class AudioFileReader(filePath: String)

Reads and decodes audio data from a file on disk or a remote URL.

The reader decodes compressed formats (MP3, AAC, M4A) into PCM float samples normalized to the range [-1.0, 1.0]. Samples are interleaved when the file contains multiple channels (left, right, left, right, ...).

Supported formats

Threading

A single AudioFileReader instance is not thread-safe. Do not call readAll, readFrames, or seekTo concurrently from multiple threads. If you need to read the same file from multiple threads, create a separate reader per thread.

Usage

// Read an entire file at once
val reader = AudioFileReader("/path/to/audio.wav")
val info = reader.info
println("Duration: ${info.durationMs} ms, Channels: ${info.channelCount}")
val samples = reader.readAll()
reader.close()

// Stream in chunks (useful for large files)
val reader2 = AudioFileReader("https://example.com/audio.m4a")
while (!reader2.isAtEnd) {
val chunk = reader2.readFrames(4096)
// process chunk ...
}
reader2.close()

Always call close when finished to release native resources.

Parameters

filePath

Absolute path to a local file, or an HTTP/HTTPS URL. On JS the path must already be in the in-memory store (decodeAudioFile, putWavBytes, putAudioFile, or a previous AudioFileWriter).

See also

Throws

if the file cannot be opened or the format is not recognized.

actual class AudioFileReader(filePath: String)

Reads and decodes audio data from a file on disk or a remote URL.

The reader decodes compressed formats (MP3, AAC, M4A) into PCM float samples normalized to the range [-1.0, 1.0]. Samples are interleaved when the file contains multiple channels (left, right, left, right, ...).

Supported formats

Threading

A single AudioFileReader instance is not thread-safe. Do not call readAll, readFrames, or seekTo concurrently from multiple threads. If you need to read the same file from multiple threads, create a separate reader per thread.

Usage

// Read an entire file at once
val reader = AudioFileReader("/path/to/audio.wav")
val info = reader.info
println("Duration: ${info.durationMs} ms, Channels: ${info.channelCount}")
val samples = reader.readAll()
reader.close()

// Stream in chunks (useful for large files)
val reader2 = AudioFileReader("https://example.com/audio.m4a")
while (!reader2.isAtEnd) {
val chunk = reader2.readFrames(4096)
// process chunk ...
}
reader2.close()

Always call close when finished to release native resources.

Parameters

filePath

Absolute path to a local file, or an HTTP/HTTPS URL. On JS the path must already be in the in-memory store (decodeAudioFile, putWavBytes, putAudioFile, or a previous AudioFileWriter).

See also

Throws

if the file cannot be opened or the format is not recognized.

actual class AudioFileReader(filePath: String)

Reads and decodes audio data from a file on disk or a remote URL.

The reader decodes compressed formats (MP3, AAC, M4A) into PCM float samples normalized to the range [-1.0, 1.0]. Samples are interleaved when the file contains multiple channels (left, right, left, right, ...).

Supported formats

Threading

A single AudioFileReader instance is not thread-safe. Do not call readAll, readFrames, or seekTo concurrently from multiple threads. If you need to read the same file from multiple threads, create a separate reader per thread.

Usage

// Read an entire file at once
val reader = AudioFileReader("/path/to/audio.wav")
val info = reader.info
println("Duration: ${info.durationMs} ms, Channels: ${info.channelCount}")
val samples = reader.readAll()
reader.close()

// Stream in chunks (useful for large files)
val reader2 = AudioFileReader("https://example.com/audio.m4a")
while (!reader2.isAtEnd) {
val chunk = reader2.readFrames(4096)
// process chunk ...
}
reader2.close()

Always call close when finished to release native resources.

Parameters

filePath

Absolute path to a local file, or an HTTP/HTTPS URL. On JS the path must already be in the in-memory store (decodeAudioFile, putWavBytes, putAudioFile, or a previous AudioFileWriter).

See also

Throws

if the file cannot be opened or the format is not recognized.

actual class AudioFileReader(filePath: String)

watchOS implementation of AudioFileReader.

The Kotlin/Native watchOS bindings do not include the ExtAudioFile APIs required for audio file decoding. File reading is not supported on watchOS. Use AudioStream for real-time audio I/O instead.

actual class AudioFileReader(filePath: String)

watchOS implementation of AudioFileReader.

The Kotlin/Native watchOS bindings do not include the ExtAudioFile APIs required for audio file decoding. File reading is not supported on watchOS. Use AudioStream for real-time audio I/O instead.

Constructors

Link copied to clipboard
actual constructor(filePath: String)

Opens the audio file at filePath for reading.

actual constructor(filePath: String)

Opens the audio file at filePath for reading.

expect constructor(filePath: String)

Opens the audio file at filePath for reading.

actual constructor(filePath: String)

Opens the audio file at filePath for reading.

actual constructor(filePath: String)

Opens the audio file at filePath for reading.

actual constructor(filePath: String)

Opens the audio file at filePath for reading.

actual constructor(filePath: String)
actual constructor(filePath: String)

Properties

Link copied to clipboard
actual val info: AudioFileInfo

Metadata and format information for the opened file.

actual val info: AudioFileInfo

Metadata and format information for the opened file.

expect val info: AudioFileInfo

Metadata and format information for the opened file.

actual val info: AudioFileInfo

Metadata and format information for the opened file.

actual val info: AudioFileInfo

Metadata and format information for the opened file.

actual val info: AudioFileInfo

Metadata and format information for the opened file.

actual val info: AudioFileInfo

Metadata and format information for the opened file.

actual val info: AudioFileInfo

Metadata and format information for the opened file.

Link copied to clipboard
actual val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

actual val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

expect val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

actual val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

actual val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

actual val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

actual val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

actual val isAtEnd: Boolean

Whether the reader has reached the end of the audio data.

Functions

Link copied to clipboard
actual fun close()

Closes the reader and releases all associated native resources.

actual fun close()

Closes the reader and releases all associated native resources.

expect fun close()

Closes the reader and releases all associated native resources.

actual fun close()

Closes the reader and releases all associated native resources.

actual fun close()

Closes the reader and releases all associated native resources.

actual fun close()

Closes the reader and releases all associated native resources.

actual fun close()

Closes the reader and releases all associated native resources.

actual fun close()

Closes the reader and releases all associated native resources.

Link copied to clipboard
actual fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

actual fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

expect fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

actual fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

actual fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

actual fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

actual fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

actual fun readAll(): FloatArray

Reads and decodes all remaining audio frames into memory.

Link copied to clipboard
actual fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

actual fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

expect fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

actual fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

actual fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

actual fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

actual fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

actual fun readFrames(maxFrames: Int): FloatArray

Reads up to maxFrames audio frames from the current position.

Link copied to clipboard
actual fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.

actual fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.

expect fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.

actual fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.

actual fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.

actual fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.

actual fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.

actual fun seekTo(framePosition: Long)

Seeks to the specified frame position in the audio data.