Batch Convert WAV to a-law or u-law on a Mac

So I’ve been having to do a few conversions of WAV files for old phone systems that require either u-law or a-law encoded audio a bit lately. I’ve been using sox in terminal but decided I need to speed things up a little so decided to create a shell script to process the audio.

On a Mac with this simple script all you need to do is to dowload SoX and put the sox folder at the base level of your filesystem (on your mac HD) at /sox. You can change this in the script by altering the soxloc=”/sox/sox”; line

Then all you need to do is open the Terminal and first drag the script on to the window. Then just drag the folder that contains all the audio files and hit enter.

The script will start looping through the files and converting each one.

You can change any of the parameters like sample rate or encoding just by altering the “-r 8000 -c 1 -e u-law” part

#! /bin/sh

echo "WAV to u-law converter script by Sandy Milne V1" 

shopt -s nullglob
for f in "$1"/*.wav
	echo "Processing - $f"
	"$soxloc" "$f" -r 8000 -c 1 -e u-law "${f%.*}"-ulaw.wav

You can download the script here:

Hope it’s useful.

Leave a Reply

Your email address will not be published. Required fields are marked *