April 2, 2017 · music SoX utility

Audio files batch conversion with SoX

Here's what I do when I have a bunch of aif files that need to become wav files. You will need  SoX to do this.


#! /bin/sh 
cd $1
mkdir aif
for file in *.aif do
 	#echo $file 	
    #echo $name
    #echo $wave 	
    sox $file $wave 	
    mv $file aif

The first argument to the script is the directory to use. The echo statements are to see and debug the values of the variables. An "aif" folder is created in your sound file folder, and the aifs are moved there after conversion.


And here's what I do for 32- or 24-bit files that need to become 16-bits. You could add in the copying trick as above if you wanted to copy the files with the wrong bit-rate to a directory just in case you needed the higher bit-rate versions in the future.

#! /bin/sh
cd $1 
for file in *.aif do
    sox $file ${name}_16.wav 

You can easily be copying in place if you change the arguments slightly, so be careful. ([bt] is a backtick, since markdown will not allow that character.)


SoX is also great for converting sound files to Layer 2 MP3 files. This is required for MP3s to be loaded by certain programming libraries. It's quite easy.

sox foo.aif foo.mp3

This all depends on SoX, a great little command-line program for miscellaneous audio tasks. Check it out if you don't already know it. In theory you could produce music using just this tool, if you absolutely had to...

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket