SoX is a command-line audio processing tool that can convert, apply effects, and play audio files in various formats.
This repository includes build scripts for compiling SoX with statically linked codec libraries, producing a single portable executable.
Required:
- Visual Studio 2019 or 2022 (with C++ workload)
- CMake 3.14 or later
- Git (optional, for cloning)
CMake is usually included with Visual Studio. If not, install it from https://cmake.org/download/
Installation:
# Visual Studio Installer > Modify > Workloads > "Desktop development with C++"
# CMake is included with Visual Studio C++ toolsRequired:
sudo apt-get update
sudo apt-get install -y build-essential cmake git curlOptional (for audio drivers):
# ALSA (recommended)
sudo apt-get install -y libasound2-dev
# PulseAudio
sudo apt-get install -y libpulse-dev
# For AMR support
sudo apt-get install -y libopencore-amrnb-dev libopencore-amrwb-devRequired:
sudo dnf install -y gcc gcc-c++ make cmake git curlOptional:
# ALSA
sudo dnf install -y alsa-lib-devel
# PulseAudio
sudo dnf install -y pulseaudio-libs-develRequired:
sudo pacman -S base-devel cmake git curlOptional:
sudo pacman -S alsa-lib libpulseRequired:
# Install Xcode Command Line Tools
xcode-select --install
# Install Homebrew (if not installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install dependencies
brew install cmakeOptional:
# For autoreconf (needed by some libraries)
brew install autoconf automake libtoolRequired:
sudo pkg install cmake git curl gmakeRequired:
sudo pkgin install cmake git curlRequired:
doas pkg_add cmake git curlWindows (PowerShell):
cd C:\path\to\sox-repo
.\build_static_libs.ps1Linux/macOS/BSD (Bash):
cd /path/to/sox-repo
chmod +x build_static_libs.sh
./build_static_libs.sh-
Clone or download the repository:
git clone <repository-url> cd sox-repo
-
Run the build script:
The script will automatically:
- Download all required codec libraries
- Compile each library as a static library
- Configure and build SoX with all codecs
- Copy the final binary to the
output/directory - Clean up temporary build files
-
Find the output:
- Windows:
output\sox.exe - Linux/macOS/BSD:
output/sox
- Windows:
Windows:
# Build without MP2 and ID3 tag support
.\build_static_libs.ps1 -NoMp2 -NoId3tag
# Build with 4 parallel jobs
.\build_static_libs.ps1 -Jobs 4
# Clean build directories
.\build_static_libs.ps1 -CleanLinux/macOS/BSD:
# Build without AMR and MP2 support
./build_static_libs.sh --no-amr --no-mp2
# Build with 4 parallel jobs
./build_static_libs.sh --jobs 4
# Add PulseAudio support (Linux)
./build_static_libs.sh --with-pulseaudio
# Clean build directories
./build_static_libs.sh --clean| Codec | Description | Libraries |
|---|---|---|
| OGG/Vorbis | Ogg container with Vorbis audio | libogg, libvorbis |
| FLAC | Free Lossless Audio Codec | libFLAC |
| Opus | Modern low-latency codec | libopus, opusfile |
| MP3 | MPEG Audio Layer III | libmad (decoder), LAME (encoder) |
| MP2 | MPEG Audio Layer II | TwoLAME (encoder) |
| WavPack | Lossless audio compression | libwavpack |
| libsndfile | Multi-format audio I/O | libsndfile |
| ID3 Tag | MP3 metadata support | libid3tag |
| PNG | Spectrogram output | libpng, zlib |
| Codec | Description |
|---|---|
| AMR | Adaptive Multi-Rate audio |
| libmagic | File type detection |
| Platform | Default Drivers |
|---|---|
| Windows | WaveAudio |
| Linux | ALSA + libao |
| macOS | CoreAudio + libao |
| FreeBSD | OSS + libao |
| NetBSD | OSS + libao |
| OpenBSD | OSS + libao |
| Argument | Description |
|---|---|
-Jobs N |
Number of parallel build jobs (default: auto) |
-Clean |
Remove all build and output directories |
-Help |
Show help message |
Codec Exclusion:
| Argument | Description |
|---|---|
-NoOgg |
Exclude OGG/Vorbis support |
-NoFlac |
Exclude FLAC support |
-NoOpus |
Exclude Opus support |
-NoMp3 |
Exclude MP3 support (libmad + LAME) |
-NoMp2 |
Exclude MP2 support (TwoLAME) |
-NoWavpack |
Exclude WavPack support |
-NoSndfile |
Exclude libsndfile support |
-NoId3tag |
Exclude ID3 tag support |
-NoPng |
Exclude PNG spectrogram support |
Audio Drivers:
| Argument | Description |
|---|---|
-NoWaveaudio |
Exclude WaveAudio driver |
| Argument | Description |
|---|---|
--jobs N, -j N |
Number of parallel build jobs (default: auto) |
--clean |
Remove all build and output directories |
--help, -h |
Show help message |
Codec Exclusion:
| Argument | Description |
|---|---|
--no-ogg |
Exclude OGG/Vorbis support |
--no-flac |
Exclude FLAC support |
--no-opus |
Exclude Opus support |
--no-mp3 |
Exclude MP3 support (libmad + LAME) |
--no-mp2 |
Exclude MP2 support (TwoLAME) |
--no-wavpack |
Exclude WavPack support |
--no-sndfile |
Exclude libsndfile support |
--no-amr |
Exclude AMR support |
--no-id3tag |
Exclude ID3 tag support |
--no-png |
Exclude PNG spectrogram support |
--no-magic |
Exclude libmagic support |
Audio Driver Exclusion:
| Argument | Description |
|---|---|
--no-alsa |
Exclude ALSA driver |
--no-ao |
Exclude libao driver |
--no-coreaudio |
Exclude CoreAudio driver (macOS) |
--no-oss |
Exclude OSS driver |
Audio Driver Inclusion:
| Argument | Description |
|---|---|
--with-alsa |
Include ALSA driver |
--with-coreaudio |
Include CoreAudio driver |
--with-pulseaudio |
Include PulseAudio driver |
--with-oss |
Include OSS driver |
After the build completes, verify the installation:
# Windows
.\output\sox.exe --version
# Linux/macOS/BSD
./output/sox --versionExpected output:
sox: SoX v14.4.3
# Windows
.\output\sox.exe --help-format all
# Linux/macOS/BSD
./output/sox --help-format allThis will list all supported audio formats. Look for:
flac- FLAC supportmp3- MP3 supportogg- OGG/Vorbis supportopus- Opus supportwav- WAV supportwavpack- WavPack support
# Windows
.\output\sox.exe --help-device all
# Linux/macOS/BSD
./output/sox --help-device all# Convert a WAV file to MP3
./output/sox input.wav output.mp3
# Convert a WAV file to FLAC
./output/sox input.wav output.flac
# Generate a test tone (5 seconds, 440Hz sine wave)
./output/sox -n test.wav synth 5 sine 440# Linux: Check for dynamic dependencies
ldd ./output/sox
# macOS: Check for dynamic dependencies
otool -L ./output/soxOn Linux, a statically compiled binary should show only system libraries like:
linux-vdso.solibc.solibm.solibpthread.solibdl.solibasound.so(if ALSA enabled)
On macOS, you should see only system frameworks:
CoreAudio.frameworklibSystem.B.dylib
# Generate and play a test tone
./output/sox -n -d synth 3 sine 440
# Play an audio file
./output/sox input.wav -dCMake not found (Windows):
- Ensure Visual Studio is installed with C++ workload
- Or install CMake separately and add to PATH
Build fails with missing headers (Linux):
- Install development packages:
sudo apt-get install libasound2-dev
Permission denied (Linux/macOS):
- Make script executable:
chmod +x build_static_libs.sh
Homebrew not found (macOS):
- Install Homebrew first (see macOS dependencies section)
autoreconf not found (macOS):
- Install autotools:
brew install autoconf automake libtool
If you encounter issues, try a clean build:
# Windows
.\build_static_libs.ps1 -Clean
.\build_static_libs.ps1
# Linux/macOS/BSD
./build_static_libs.sh --clean
./build_static_libs.shThe build scripts download and compile the following library versions:
| Library | Version |
|---|---|
| zlib | 1.3.1 |
| libpng | 1.6.43 |
| libogg | 1.3.5 |
| libvorbis | 1.3.7 |
| FLAC | 1.4.3 |
| opus | 1.5.2 |
| opusfile | 0.12 |
| libmad | 0.15.1b |
| LAME | 3.100 |
| TwoLAME | 0.4.0 |
| libid3tag | 0.15.1b |
| WavPack | 5.7.0 |
| libsndfile | 1.2.2 |
| opencore-amr | 0.1.6 |
| file/libmagic | 5.45 |
| libtool/libltdl | 2.4.7 |
| libao | 1.2.2 |
SoX is distributed under the GNU General Public License (GPL) and GNU Lesser General Public License (LGPL). See LICENSE.GPL and LICENSE.LGPL for details.