Useful application to convert sound files between different formats.
From the website:
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 writes a 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 do 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 sox compiled with GSM support 🙁
- SoX is now maintained by a different author. There have been many improvements, as well. You can visit the new home page for SoX at http://sox.sourceforge.net/
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
- !/bin/bash
echo “** THIS SCRIPT REQUIRES LAME AND SOX TO WORK!**”
- Convert mp3 files to wav
for i in *.mp3; do
val=${i%.mp3}
echo “** Converting mp3 to wav files if they exist”
lame –decode “$i” “$val.wav”
rm -f “$i”
echo “** $i MP3 to WAV is complete”
done
- Convert wav files
for i in *.wav; do
val=${i%.wav}
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”
done
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
- WavePad: Sound recorder and batch converter
- On-line audio conversion by asteriskguru.com, including G729 and g723 formats
- Asterisk sound files – example on how to convert from .wav to .gsm with sox
- Asterisk audio convert module – Loadable module for Asterisk to convert Asterisk audio formats from the * CLI – very cool!