AudioFileWriter
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Encodes and writes audio data to a file on disk.
The writer accepts PCM float samples normalized to the range [-1.0, 1.0] and encodes them into the specified AudioFileFormat. Samples must be interleaved when writing multi-channel audio (left, right, left, right, ...).
Supported output formats
AudioFileFormat.WAV -- Uncompressed PCM on every platform (JS is in-memory). Produces the largest files but avoids encoding latency.
AudioFileFormat.AAC / AudioFileFormat.M4A -- Android and iOS/macOS/tvOS only. JVM, native desktop, JS, and watchOS throw UnsupportedFormatException.
AudioFileFormat.MP3 -- Encoding throws UnsupportedFormatException on every platform.
Threading
A single AudioFileWriter instance is not thread-safe. Do not call writeFrames concurrently from multiple threads.
Usage
// Write a WAV file with metadata
val writer = AudioFileWriter(
filePath = "/path/to/output.wav",
format = AudioFileFormat.WAV,
sampleRate = 44100,
channelCount = 2,
tags = AudioFileTags(title = "My Recording", artist = "Klarinet"),
)
writer.writeFrames(samples, frameCount)
writer.close() // must close to finalize the file headerAlways call close when finished to flush any buffered data and release native resources. Failing to close the writer may result in a corrupt or incomplete output file.
Parameters
Absolute path for the output file. Parent directories must already exist.
The audio container/codec format to use.
The sample rate in Hz (e.g. 44100, 48000).
The number of audio channels (1 = mono, 2 = stereo).
Optional metadata tags to embed in the file. Pass null (the default) to omit metadata.
See also
Throws
if the file cannot be created.
if the format is not supported on the current platform.
Constructors
Creates a new audio file at filePath.
Creates a new audio file at filePath.
Creates a new audio file at filePath.
Creates a new audio file at filePath.
Creates a new audio file at filePath.
Creates a new audio file at filePath.
Creates a new audio file at filePath.
Creates a new audio file at filePath.
Functions
Closes the writer, flushing any buffered data and releasing resources.
Closes the writer, flushing any buffered data and releasing resources.
Closes the writer, flushing any buffered data and releasing resources.
Closes the writer, flushing any buffered data and releasing resources.
Closes the writer, flushing any buffered data and releasing resources.
Closes the writer, flushing any buffered data and releasing resources.
Closes the writer, flushing any buffered data and releasing resources.
Closes the writer, flushing any buffered data and releasing resources.
Writes audio frames to the file.
Writes audio frames to the file.
Writes audio frames to the file.
Writes audio frames to the file.
Writes audio frames to the file.
Writes audio frames to the file.
Writes audio frames to the file.
Writes audio frames to the file.