AudioFileWriter

actual class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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.

actual class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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.

expect class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags? = null)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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.

actual class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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.

actual class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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.

actual class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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.

actual class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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.

actual class AudioFileWriter(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

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

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 header

Always 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

filePath

Absolute path for the output file. Parent directories must already exist.

format

The audio container/codec format to use.

sampleRate

The sample rate in Hz (e.g. 44100, 48000).

channelCount

The number of audio channels (1 = mono, 2 = stereo).

tags

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

Link copied to clipboard
actual constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

Creates a new audio file at filePath.

actual constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

Creates a new audio file at filePath.

expect constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags? = null)

Creates a new audio file at filePath.

actual constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

Creates a new audio file at filePath.

actual constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

Creates a new audio file at filePath.

actual constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

Creates a new audio file at filePath.

actual constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

Creates a new audio file at filePath.

actual constructor(filePath: String, format: AudioFileFormat, sampleRate: Int, channelCount: Int, tags: AudioFileTags?)

Creates a new audio file at filePath.

Functions

Link copied to clipboard
actual fun close()

Closes the writer, flushing any buffered data and releasing resources.

actual fun close()

Closes the writer, flushing any buffered data and releasing resources.

expect fun close()

Closes the writer, flushing any buffered data and releasing resources.

actual fun close()

Closes the writer, flushing any buffered data and releasing resources.

actual fun close()

Closes the writer, flushing any buffered data and releasing resources.

actual fun close()

Closes the writer, flushing any buffered data and releasing resources.

actual fun close()

Closes the writer, flushing any buffered data and releasing resources.

actual fun close()

Closes the writer, flushing any buffered data and releasing resources.

Link copied to clipboard
actual fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.

actual fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.

expect fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.

actual fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.

actual fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.

actual fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.

actual fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.

actual fun writeFrames(data: FloatArray, numFrames: Int)

Writes audio frames to the file.