flexaudio-encode
Streaming FLAC recording sink for Rust. Feed interleaved f32 audio chunks
as they arrive and they are compressed losslessly to a .flac file on the fly —
a 3-hour meeting recording that would be ~2 GB as WAV lands at roughly a third
to a half of that, bit-exact at 16-bit. Encoding is pure Rust (flacenc), runs
fully offline, and memory usage stays constant no matter how long the
recording gets.
This crate is independent of flexaudio-core: it consumes a plain &[f32]
sample stream, so you can pair it with any audio source.
Example
use FlacWriter;
let mut writer = create?;
for chunk in some_audio_chunks
writer.finalize?; // flushes the tail and fixes up the STREAMINFO header
With flexaudio
AudioChunk.data is already interleaved f32 in the output format, so it can
be passed straight through:
use ;
use FlacWriter;
let config = StreamConfig ;
let mut stream = open?;
// flexaudio's default output format is 48 kHz / stereo.
let mut writer = create?;
stream.start?;
while !done
stream.stop;
writer.finalize?;
Notes
- Samples are quantized from
f32to 16-bit (simple rounding with clamping, no dither). 1–2 channels, sample rates up to 96 kHz. finalize()is recommended: it reports I/O errors and rewrites the header with the final sample count and MD5. Dropping the writer without finalizing closes the file on a best-effort basis (errors are swallowed).- Encoding runs synchronously on the calling thread.
Install
License & third-party notices
MIT © 2026 tubome / Studio Sadola.
This crate links flacenc (Apache-2.0), a pure-Rust FLAC encoder; binaries embedding this crate include flacenc code under Apache-2.0 terms. Tests additionally use the claxon decoder (Apache-2.0, dev-dependency only, not distributed).