AudioFlow

class AudioFlow(val format: AudioFormat, data: Flow<ByteArray>) : Flow<ByteArray>

A typed stream of raw PCM audio: an AudioFormat paired with a Flow of ByteArray chunks.

Every emitted chunk is PCM in format: same sample rate, channel count, and sample encoding. Chunk boundaries are arbitrary; consumers must treat the stream as one continuous byte sequence.

The wrapped Flow may be cold or hot. A cold flow re-emits its full sequence on each collector (typical for replayable recordings). A hot flow shares live emissions among concurrent collectors (typical while recording). format always describes the PCM layout of every chunk, regardless of cold or hot behavior.

Constructors

Link copied to clipboard
constructor(format: AudioFormat, data: Flow<ByteArray>)

Properties

Link copied to clipboard

PCM layout shared by every chunk in the wrapped flow.

Functions

Link copied to clipboard
open suspend override fun collect(collector: FlowCollector<ByteArray>)
Link copied to clipboard
suspend fun AudioFlow.collectAsBuffer(format: AudioFileFormat): Buffer

Collects this flow and returns an in-memory buffer containing the encoded file bytes for format (WAV, AIFF, or AU).

Link copied to clipboard

Collects every chunk from this flow into one contiguous PCM buffer wrapped as an AudioSource with this flow's AudioFlow.format.

Link copied to clipboard

Convert an AudioFlow to a different AudioFormat. Pipeline: bytes -> normalized samples -> resample -> channel convert -> bytes

Link copied to clipboard
suspend fun AudioFlow.writeToFile(format: AudioFileFormat, path: Path)

Collects this flow and writes the PCM data to a file at path.

Link copied to clipboard
suspend fun AudioFlow.writeToSink(format: AudioFileFormat, sink: Sink)

Collects this flow and writes the PCM data to sink in the chosen file format (WAV, AIFF, or AU).