wav_io 0.1.17

Wav file reader and writer
Documentation

wav_io for Rust

This crate provides utilities for reading and writing WAV files.

Supported formats

  • PCM 8-, 16-, 24-, and 32-bit integer
  • PCM 32- and 64-bit float

Functions

Installation

Add wav_io to your project:

cargo add wav_io

Samples

use std::f32::consts::PI;
fn main() {
    // make sine wave
    let head = wav_io::new_mono_header();
    let mut samples: Vec<f32> = vec![];
    for t in 0..head.sample_rate {
        let v = ((t as f32 / head.sample_rate as f32) * 440.0 * 2.0 * PI).sin() * 0.6;
        samples.push(v);
    }
    // write to file
    let mut file_out = std::fs::File::create("./sine.wav").unwrap();
    wav_io::write_to_file(&mut file_out, &head, &samples).unwrap();
}

Examples

CLI

Build and run the bundled CLI:

cargo run -- help

Basic commands:

# Show WAV header and sample length
cargo run -- info ./input.wav

# Generate a WAV from MML text
cargo run -- mml ./melody.wav "o5 l8 cdefgab>c"

# Split by silence and write files to a directory
cargo run -- split ./input.wav ./a_split

# Resample to a new sample rate (Hz)
cargo run -- resample ./input.wav 16000 ./output_16k.wav

Debug option:

# -d or --debug can be placed after the command
cargo run -- info --debug ./input.wav

Links