AudioFileReader
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
AudioFileFormat.WAV / AudioFileFormat.MP3 -- Android, iOS/macOS/tvOS, JVM, and native desktop. JS after
decodeAudioFile/putWavBytes/putAudioFile. Not available on watchOS.AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS; JS after decode. JVM, native desktop, and watchOS throw UnsupportedFormatException.
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
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.
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
AudioFileFormat.WAV / AudioFileFormat.MP3 -- Android, iOS/macOS/tvOS, JVM, and native desktop. JS after
decodeAudioFile/putWavBytes/putAudioFile. Not available on watchOS.AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS; JS after decode. JVM, native desktop, and watchOS throw UnsupportedFormatException.
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
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.
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
AudioFileFormat.WAV / AudioFileFormat.MP3 -- Android, iOS/macOS/tvOS, JVM, and native desktop. JS after
decodeAudioFile/putWavBytes/putAudioFile. Not available on watchOS.AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS; JS after decode. JVM, native desktop, and watchOS throw UnsupportedFormatException.
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
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.
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
AudioFileFormat.WAV / AudioFileFormat.MP3 -- Android, iOS/macOS/tvOS, JVM, and native desktop. JS after
decodeAudioFile/putWavBytes/putAudioFile. Not available on watchOS.AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS; JS after decode. JVM, native desktop, and watchOS throw UnsupportedFormatException.
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
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.
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
AudioFileFormat.WAV / AudioFileFormat.MP3 -- Android, iOS/macOS/tvOS, JVM, and native desktop. JS after
decodeAudioFile/putWavBytes/putAudioFile. Not available on watchOS.AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS; JS after decode. JVM, native desktop, and watchOS throw UnsupportedFormatException.
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
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.
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
AudioFileFormat.WAV / AudioFileFormat.MP3 -- Android, iOS/macOS/tvOS, JVM, and native desktop. JS after
decodeAudioFile/putWavBytes/putAudioFile. Not available on watchOS.AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS; JS after decode. JVM, native desktop, and watchOS throw UnsupportedFormatException.
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
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.
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.
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.
Properties
Metadata and format information for the opened file.
Metadata and format information for the opened file.
Metadata and format information for the opened file.
Metadata and format information for the opened file.
Metadata and format information for the opened file.
Metadata and format information for the opened file.
Metadata and format information for the opened file.
Metadata and format information for the opened file.
Functions
Closes the reader and releases all associated native resources.
Closes the reader and releases all associated native resources.
Closes the reader and releases all associated native resources.
Closes the reader and releases all associated native resources.
Closes the reader and releases all associated native resources.
Closes the reader and releases all associated native resources.
Closes the reader and releases all associated native resources.
Closes the reader and releases all associated native resources.
Reads and decodes all remaining audio frames into memory.
Reads and decodes all remaining audio frames into memory.
Reads and decodes all remaining audio frames into memory.
Reads and decodes all remaining audio frames into memory.
Reads and decodes all remaining audio frames into memory.
Reads and decodes all remaining audio frames into memory.
Reads and decodes all remaining audio frames into memory.
Reads and decodes all remaining audio frames into memory.
Reads up to maxFrames audio frames from the current position.
Reads up to maxFrames audio frames from the current position.
Reads up to maxFrames audio frames from the current position.
Reads up to maxFrames audio frames from the current position.
Reads up to maxFrames audio frames from the current position.
Reads up to maxFrames audio frames from the current position.
Reads up to maxFrames audio frames from the current position.
Reads up to maxFrames audio frames from the current position.