Bash Script – Convert a Batch of WAV Files to SLINEAR Format for Asterisk Hold Music

Here are a couple of useful one-liners that I picked up from a while back to manipulate a bunch of audio files in a single directory with Sox. You can save yourself some processing power on your Asterisk PBX if all of your hold music is in SLINEAR format that way no transcoding has to take place.

To decrease the volume level on all wav files in a directory:

for a in *.wav; do sox -v -.1 "$a" `echo $a|sed "s/.wav/new.wav/"`; done

To convert new wav files from wav to slinear format that Asterisk likes:

for a in *new.wav; do sox "$a" -t raw -r 8000 -s -2 -c 1 `echo $a|sed "s/new.wav/.sln/"` resample -ql; done

02/15/2015 – I revisited this issue today with Sox version 14.4.1 and found that a bunch of the options have been deprecated and that the conversion script no longer worked, so here is the new command:

for a in *new.wav; do sox "$a" -t raw -r 8000 -e signed-integer -b 16 -c 1 `echo $a|sed "s/new.wav/.sln/"` rate -ql; done

Leave a Reply