How to Edit Audio via Command Line Using SoX

Written by

in

SoX (Sound eXchange) is a powerful command-line utility for audio editing. It works on Windows, Mac, and Linux.

Here is how to convert, trim, and mix audio files using SoX. Convert Audio Files

SoX changes file formats based on the file extensions you provide in the command. Convert WAV to MP3: sox input.wav output.mp3 Convert MP3 to OGG: sox input.mp3 output.ogg

Change sample rate to 44.1kHz: sox input.wav -r 44100 output.wav Convert stereo to mono: sox input.wav -c 1 output.wav Trim Audio Files

The trim effect cuts audio using start times and durations. Format positions as seconds (e.g., 12) or HH:MM:SS (e.g., 00:01:30).

Extract the first 10 seconds: sox input.wav output.wav trim 0 10

Cut from 30 seconds to the end: sox input.wav output.wav trim 30

Extract from 1 minute to 1 minute 15 seconds: sox input.wav output.wav trim 60 15 Mix Audio Files SoX can combine multiple audio files into a single track.

Mix files into one track: sox -m input1.wav input2.wav output.wav

Mix with individual volume adjustments: sox -m -v 0.8 input1.wav -v 0.5 input2.wav output.wav

Merge two mono files into one stereo file: sox -M left.wav right.wav stereo.wav Combine Multiple Operations

You can chain these commands together to process audio in one single line. Trim and convert a file: sox input.wav output.mp3 trim 10 5

Mix, downsample, and convert: sox -m input1.wav input2.wav -r 16000 output.mp3

We can also explore how to add audio effects like fade-ins, normalization, or reverb. If you have a specific batch conversion script you want to create for multiple files, let me know so I can write the code for you.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *