How to install and use Sound eXchange

How to install and use Sound eXchange

with 3 Comments

Sound eXchange (SoX) is a command-line audio editing utility. I find it useful for quickly editing large batches of audio files. This is how to install it on a Mac, with a few examples on how to use it.

Obtaining and installing SoX

Note: Xcode may need to be installed on your computer.

https://developer.apple.com/xcode/

Download the latest version of SoX in tar.gz format (when I installed it, the latest version was sox-14.4.1.tar.gz).

https://sourceforge.net/projects/sox/files/sox/

Without unarchiving it, move the file to your home directory.

Launch the Terminal app (found at /Applications/Utilities/Terminal.app).

Do a checksum to check the integrity of the file by entering the following in Terminal:

openssl sha1 sox-14.4.1.tar.gz

Note: Replace “sox-14.4.1.tar.gz” with the name of the version you downloaded.

It will return something like the following:

71f05afc51e3d9b03376b2f98fd452d3a274d595

Compare this to what is found at SourceForge under SHA1 (click on the “i” icon on the download link). They should match.

Unarchive the the tar.gz file by invoking the following command in Terminal:

tar xzvf sox-14.4.1.tar.gz

Run the configure script by entering each of the following commands in sequence in Terminal (make sure to replace “sox-14.4.1” with the name of your version):

cd sox-14.4.1
./configure
make -s
sudo make install

Put in your password.

Make sure everything installed correctly by invoking the following:

sox -h

If it installed correctly, the SoX version number and a help file will be output.

You can erase the tar.gz file and the unarchived file from your home folder.

Examples

Note: These examples assume that the audio file(s) you want to edit are in your home folder (unless otherwise noted). Also be sure that you use the correct audio format suffix. In some of the examples I use .wav and sometimes .aif, just edit your commands according to what you have.


To convert the sample rate of a file:

sox "input.wav" "output.wav" rate -v 48000

The target sample rate is at the end (in this example, and in all the examples, the original sample rate was 96kHz). Quotes are useful around file or path names that have spaces, otherwise the spaces must be escaped with a backslash (see an example below).


To batch convert the sample rate of one or more files:

for i in *.wav; do sox -S "${i}" "48k ${i}" rate -v 48000; done

This version keeps the new files in the same folder as the old files, but it puts “48k” in the front of the new files. It shows the progress of the conversion (that is the purpose of the “-S” flag; this can also be done using the “–show-progress” flag).

for i in *.wav; do sox -S "${i}" 48kVersions/"48k ${i}" rate -v -L -s 48000; done

This version will convert all the .wav files in the home directory, tack “48k” on the front and put them in a folder called “48kVersions” (make sure you have a folder called “48kVersions” in the home directory). It will also show the progress of the conversion in the Terminal window. Rate is also set to very high quality, linear phase response, and steep filter.


To get sound file info:

sox input.wav -n stat
sox input.wav -n stats

“Stat” and “stats” provide different info.


Time stretch:

sox input.wav output.wav tempo -m 0.1

<1 = stretch, >1 = compress. Use the -m flag for music.


Low-pass filter starting at 38kHz of one or more files:

for i in *.aif; do sox --show-progress "${i}" "38kHz L Pass ${i}" sinc -38k; done

This version keeps the new file in the same folder and puts text at the front of the file.

for i in *.aif; do sox --show-progress "${i}" "38kHz L Pass ${i}" sinc -L -38k; done

In this option, the filter’s phase response is linear.

for i in *.aif; do sox --show-progress "${i}" "Low Pass 2 ${i}" lowpass 38k; done

This version does the same as previous, but uses a different filter. This version puts the words “Low Pass 2” in front of the new file(s). This version does not have as steep of a roll-off.


Shifting the pitch but not changing the speed of multiple files:

for i in *.aif; do sox --show-progress "${i}" "+38cents ${i}" pitch 38; done

This version keeps the new file in the same folder and puts text at the front of the file. This raises the pitch by 38 cents.

sox -S "AKG Tremolo 1.aif" "Dwn100c using pitch AKG Tremolo 1.aif" pitch -100

This version changes the pitch of a single file. This lowers the pitch by a semitone. This pitch is measured in cents.


Doing multiple effects on multiple files with a single command:

for i in *.aif; do sox --show-progress "${i}" "38kHz LPF Up11Cents ${i}" sinc -38k pitch 11; done

This applies a low-pass filter at 38kHz and raises the pitch by 11 cents.


Read from other than the home folder (note the use and non-use of quotes and escaped spaces); and do multiple procedures on a single file with a single command:

sox -S /Users/name/Desktop/Samples/Original\ Samples/AKG\ Tremolo\ 1.aif "38kHzLPF Dwn48Cents A5 AKG Tremolo 1.aif" sinc -38k pitch -48

This applies a low-pass filter at 38kHz and lowers the pitch by 48 cents.


Change the pitch and time by changing just the sample information of a single file:

sox -S "AKG Tremolo 1.aif" "Dwn2400c AKG Tremolo 1.aif" speed -2400c rate -v 96k

This changes pitch and duration. Recall that the original sample rate in all these examples was 96kHz. “Technically, the speed effect only changes the sample rate information, leaving the samples themselves untouched. The rate effect is invoked automatically to resample to the output sample rate, using its default quality/speed. For higher quality or higher speed resampling, in addition to the speed effect, specify the rate effect with the desired quality option.”1 In this instance it is set on very high quality.

sox -S "AKG Tremolo 1.aif" "Dwn2400c Linear and Steep AKG Tremolo 1.aif" speed -2400c rate -v -L -s 96k

This example does the same as the previous, however, rate is set to very high quality, linear phase response, and steep filter.


Low-pass filter and tune multiple files:

for i in *.aif; do sox -S "${i}" "A5 38kHzLP ${i}" sinc -L -38k speed -48c rate -v -L -s 96k; done

Low-pass filter at 38kHz, drop the pitch by 48 cents, resample at the original sample rate, and rename the files.


Apply a fade on a single file:

sox -S "Filein.wav" "Fileout.wav" fade t 0 0 0:0:0.75t

750ms fade out using a linear (i.e., triangular) shape. There is no fade in and no truncation at the end.


High-pass filter multiple files:

for i in *.wav; do sox -S "${i}" "200HzHP ${i}" sinc -L -t 15 200; done

200Hz high-pass filter, with a linear response, and a transition bandwidth of 15Hz.

for i in *.wav; do sox -S "${i}" "200HzHP ${i}" highpass -2 200 0.707q; done

200Hz high-pass filter. It is a less-steep filter than the previous.


Low-pass filter and fade out multiple files:

for i in *.wav; do sox -S "${i}" "18kHzLP FdOut ${i}" sinc -L -18k fade t 0 0 0:0:0.75t; done

Low-pass filter at 18kHz with a linear response. Fade-out for 750ms with a linear shape, no fade in, and no truncation at the end.


High-pass filter and transpose multiple files:

for i in *.wav; do sox -S "${i}" "40HzHP 8va ${i}" sinc -L -t 5 40 speed 1200c rate -v -L -s 96k; done

40Hz high-pass filter, with a linear response, and a transition bandwidth of 5Hz. Transpose up one octave.


Low-pass filter, tune, and reverse multiple samples:

for i in *.wav; do sox -S "${i}" "A4 38kHzLP Rev ${i}" sinc -L -38k speed 277c rate -v -L -s 96k reverse; done

38kHz low-pass filter, up 277 cents, reversed.


Sharp low-pass filter, gradual low-pass filter, high-pass filter, tune, and reverse multiple samples:

for i in *.wav; do sox -S "${i}" "A2 2kHzLP 30HzHP Rev ${i}" sinc -L -38k lowpass -2 2k 0.707q highpass -2 30 0.707q speed 150c rate -v -L -s 96k reverse; done

Sharp low-pass filter at 38kHz, gradual low-pass filter at 2kHz, gradual high-pass filter at 30Hz, up 150 cents, reverse.


Sharp low-pass filter, sharp high-pass filter, fade in, and fade out multiple samples:

for i in *.aif; do sox -S "${i}" "38kHzLP 75HzHP Fade In Out ${i}" sinc -L -38k sinc -L -t 15 75 fade t 0:0:0.02t 0 0:0:0.1t; done

Low-pass filter at 38kHz, high-pass filter at 75Hz with a transition bandwidth of 15Hz, fade in for 20ms, and fade out for 100ms.

for i in *.aif; do sox -S "${i}" "38kHzLP 75HzHP Fade Out ${i}" sinc -L -38k sinc -L -t 15 75 fade t 0 0 0:0:0.1t; done

Same as the previous, but without the fade in.


Reverse multiple files:

for i in *.wav; do sox -S "${i}" "R ${i}" reverse; done

Add silence to the end of multiple files:

for i in *.wav; do sox -S "${i}" "Padded_${i}" pad 0 600; done

This adds 600 seconds (i.e., 10 minutes) of silence to the end of the audio files.


1http://sox.sourceforge.net/sox.html

See also:

http://sox.sourceforge.net

3 Responses

  1. Raphael
    | Reply

    Hi !

    very interesting reading all over your website.
    I’m struggling here by wanting to install SoX on a Mac under 10.8.5 .
    Gettin’ to cd sox-14.4.2 all works ok but then it says for “./configure” : “-bash: ./configure: No such file or directory”
    (I did install XCode). Have you any hints to solve this ? Thank you, Raphael

    • Raphael
      | Reply

      I’ve found my false path: I did download a binary as a .zip file thinking it’s the same content as the tar.gz as they show up with the exact same file size on http://sourceforge.net/projects/sox/ . Now it’s working.

      • John
        | Reply

        Glad it worked out!

Leave a Reply