#sound #libsndfile #encoding #compression #api-bindings

sndfile

A library for reading and writing audio files

7 releases

0.1.1 Apr 29, 2022
0.1.0 Apr 29, 2022
0.0.4 Jun 3, 2020
0.0.2 Apr 5, 2020

#319 in Audio

34 downloads per month
Used in audeye

MIT license

55KB
1.5K SLoC

sndfile.rs

A safe rust wrapper of libsndfile.
With this crate, you can read or save audio files.

Travis-CI Status Latest version Documentation License

Getting Started

sndfile.rs is available on crates.io.

With minimal features:

[dependencies]
sndfile = "0.1"

With ndarray supports:

[dependencies.sndfile]
version = "0.1"
features = ["ndarray_features"]

...and see the docs for how to use it.

Example

extern crate sndfile;
extern crate ndarray;

fn main() {
  use sndfile::*;
  let mut snd = sndfile::OpenOptions::ReadOnly(ReadOptions::Auto).from_path(
    "/mnt/st4t_0/tuxzz/muz/muz0/Call My Name/13.Loow.flac"
  ).unwrap();
  let data: ndarray::Array2<f32> = snd.read_all_to_ndarray().unwrap();

  let samplerate = snd.get_samplerate();
  let n_frame = snd.len().unwrap();
  let n_channels = snd.get_channels();
  let title = snd.get_tag(TagType::Title).unwrap();
  println!("Loaded song `{}`:", title);
  println!("  Length: {:.2} seconds", n_frame as f64 / samplerate as f64);
  println!("  Sample rate: {} Hz", samplerate);
  println!("  Channel count: {}", n_channels);
  println!("  DC offset = {}", data.mean().unwrap());
}

/*
== Expected output ==
Loaded song `Loow`:
  Length: 277.06 seconds
  Sample rate: 44100 Hz
  Channel count: 2
  DC offset = 0.00018921464
*/

License

Licensed under of

Dependencies

~32–390KB