
SoX: How to Trim Audio
Updated
Learn how to trim audio files from the start, end or middle using SoX

Install SoX
Before we start, make sure you have Homebrew installed on your computer and an audio file ready in a folder. Install SoX with this command:
brew install sox
Trim a Section
First, open your terminal and navigate to the folder that has your audio file. To keep just a piece of the song, run this command:
sox input.wav output.wav trim 5 5
Just remember to replace input.wav with your actual filename, and output.wav with the name you want for the new file. The trim effect takes two numbers: the first 5 is where to start in seconds, and the second 5 is how long to keep. So this keeps five seconds, starting at the five second mark.
For a short clip, this finishes almost instantly, and SoX won't print a success message. To make sure everything worked, run soxi -d output.wav. The -d flag prints just the duration, which should read 00:00:05.00.
Trim From the Start or the End
If you leave out the second number, SoX keeps everything from your start point to the end of the file. For example, trim 5 removes the first five seconds. To cut something off the end instead, use a negative number: trim 0 -3 removes the last three seconds.
If you hear a tiny click at the edges of your clip, just add fade 0.01 0 0.01 to the end of your command to smooth out the cut.
