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.
- 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.
-
Clone the repository:
git clone https://github.com/RustedBytes/wav-files-concat cd wav-files-concat
-
Build and install:
cargo install --path .
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:
- Find all WAV files recursively.
- Validate they share the same audio spec.
- Concatenate them in the order discovered by the filesystem walker.
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.
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
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.
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.
cargo build --release
The binary will be in target/release/wav-files-concat
.