SOX - Sound Exchange

Useful application to convert sound files between different formats.

From the web site:

SoX is a sound file format converter for Unix and DOS PCs written by Lance Norskog and other invaluable contributors. It also does sample rate conversion and some sound effects. It's the swiss army knife of sound tools: the interface isn't great, but it does almost everything.

SoX uses file suffixes to determine the nature of a sound sample file. If it finds the suffix in its list, it uses the appropriate read or write handler to deal with that file. SoX has an auto-detect feature that attempts to figure out the nature of an unmarked sound sample. It works very well. This is the 'auto' file format.

If your sox does not know how to handle .gsm - Files, you will have to download the latest version and recompile. Some distributions (like SuSE 9.0) do not include a sox compiled with GSM support :-(

Sox script for normalizing and converting mp3 & wav files to an Asterisk friendly format

Here is a script to normalize and convert mp3 and wav files for to proper wav files for music on hold

It basically amplifies the volume by the max suggested amount by sox, converts to 16 bit 8000 mono wav file, and then reduces the volume by 1/2

You can't run the script on the same files twice right now, although that would be trivial to incorporate

NOTE! It deletes the mp3 files and converted files as it works. I usually copy the files to a staging directory for the conversion. If you don't want this to happen, remove the "rm -f" lines from the code!

Hope it helps someone

  1. !/bin/bash


  1. Convert mp3 files to wav

for i in *.mp3; do


echo "** Converting mp3 to wav files if they exist"

lame --decode "$i" "$val.wav"

rm -f "$i"

echo "** $i MP3 to WAV is complete"


  1. Convert wav files

for i in *.wav; do


echo "** Checking volume levels for $i"

ampl=`sox "$i" -t wav /dev/null stat -v 2>&1 | grep -v sox:`

echo "** Amplifying volume by $ampl to fake a normalize and converting $val.wav to 16 bit 8000"

sox -v "$ampl" "$i" -t wav -r 8000 -c 1 -w -s "$val.converted.wav" resample

rm -f "$val.wav"

echo "** Reducing the volume"

sox -v .5 "$val.converted.wav" "$val.wav"

rm -f "$val.converted.wav"

echo "** $i is complete"


The ".5" in "line "sox -v .5 $val.converted.wav $val.wav" is what the amount (1/2) of volume changed (half seems to be good for our music on hold volume) YMMV, feel free to change it

See also

Created by: oej, Last modification: Tue 19 of Aug, 2008 (22:35) by atlantiatech
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+