flexaudio-encode 0.2.0

Streaming FLAC encoding sink for recorded audio (pure Rust, fully offline).
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented1 out of 1 items with examples
  • Size
  • Source code size: 36.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 612.19 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Studio-Sadola/flexaudio
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • tsubome

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 flexaudio_encode::FlacWriter;

let mut writer = FlacWriter::create("meeting.flac", 48_000, 2)?;
for chunk in some_audio_chunks() {
    writer.write_chunk(chunk)?; // interleaved f32, length = frames * channels
}
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 flexaudio::{open, SourceKind, StreamConfig};
use flexaudio_encode::FlacWriter;

let config = StreamConfig { kind: SourceKind::Mic, ..Default::default() };
let mut stream = open(config)?;
// flexaudio's default output format is 48 kHz / stereo.
let mut writer = FlacWriter::create("recording.flac", 48_000, 2)?;

stream.start()?;
while !done() {
    while let Some(chunk) = stream.poll_chunk() {
        writer.write_chunk(&chunk.data)?;
    }
}
stream.stop();
writer.finalize()?;

Notes

  • Samples are quantized from f32 to 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

cargo add flexaudio-encode

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).