Skip to content

RustedBytes/wav-files-concat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wav-files-concat

A lightweight Rust CLI tool for concatenating multiple WAV files from a directory (including subdirectories) into a single output WAV file. It ensures all input files have compatible formats (channels, sample rate, and sample format) before proceeding.

Features

  • Recursively scans directories for .wav files (case-insensitive).
  • Validates format compatibility across all files.
  • Supports both float (32-bit) and int (16-bit) sample formats.
  • Handles errors gracefully with detailed context using anyhow.
  • Includes comprehensive unit tests.

Installation

From Source

  1. Clone the repository:

    git clone https://github.com/RustedBytes/wav-files-concat
    cd wav-files-concat
  2. Build and install:

    cargo install --path .

Usage

wav-files-concat <INPUT_DIR> <OUTPUT_FILE>
  • <INPUT_DIR>: Path to the directory containing WAV files (required).
  • <OUTPUT_FILE>: Path to the output WAV file (required).

The tool will:

  1. Find all WAV files recursively.
  2. Validate they share the same audio spec.
  3. Concatenate them in the order discovered by the filesystem walker.

Examples

Basic Usage

Concatenate all WAV files in ./audio/ to combined.wav:

wav-files-concat ./audio/ combined.wav

Output:

Scanning input directory for WAV files...
Found 3 WAV files.
Determining WAV format from first file...
Format: 2 channels, 44100 Hz, Float
Verifying formats of remaining files...
All files compatible.
Creating output file: combined.wav
Concatenating files...
  1/3: ./audio/track1.wav
  2/3: ./audio/subdir/track2.wav
  3/3: ./audio/track3.wav
Concatenation complete.

Error Handling

If files have incompatible formats:

Error: Incompatible WAV format in ./audio/incompatible.wav: WavSpec { channels: 1, sample_rate: 48000, bits_per_sample: 16, sample_format: Int }

If no WAV files are found:

Error: No WAV files found in the input directory

Dependencies

This project uses the following crates:

Crate Purpose Version (approx.)
anyhow Error handling with context ^1.0
clap Command-line argument parsing ^4.0
hound WAV file reading/writing ^3.5
walkdir Recursive directory traversal ^2.3
tempfile (dev) Temporary files for testing ^3.0

See Cargo.toml for exact versions.

Testing

Run the test suite:

cargo test

The tests cover:

  • Finding WAV files (including subdirs, case-insensitivity, multiples, and edge cases like no files).
  • Retrieving WAV specs from valid/invalid files.
  • Copying samples with format mismatches.

All tests use temporary directories and mock WAV files for isolation.

Building

cargo build --release

The binary will be in target/release/wav-files-concat.

About

Concatenate audio files into one file

Topics

Resources

License

Stars

Watchers

Forks

Languages