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.

AIF2WAV

#! /bin/sh 
cd $1
mkdir aif
for file in *.aif do
 	#echo $file 	
    name=basename${file}.aif
    #echo $name
    wave=${name}.wav 	
    #echo $wave 	
    sox $file $wave 	
    mv $file aif
done

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.

TO16BITS

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
    name=basename${file}.aif
    sox $file ${name}_16.wav 
done

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.)

TOMP3

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...

Show Comments

Copyright (C) 2019, Thomas Stoll, Kitefish Labs