Tuesday, May 14, 2013

converting wonky wavs to mp3s in the osx terminal commandline via sox and lame

SoX (Sound eXchange) is a promising, mutliplatform commandline tool but like too many open source projects it makes life a pain in the ass if you want to output MP3s (because of potential licensing blah blah blah). (Audacity, the general standard for audio editing for cheapskates, has a cleaner way of enabling MP3 support but it's not really usable as a commandline tool.)

Trying to get SoX running with MP3 support proved beyond me:
1. The default download doesn't have it.
2. "Sox Wrap", a UI for withs own version of SoX won't do it, outputting a 0-byte file
3. I installed "Homebrew", a tool for installing extra software on OSX. I hoped "brew install sox --with-libmp3lame" or "brew install sox --with-mad --with-lame" might do it, but no. (troublingly, I can put --with-anystupidname and homebrew doesn't report that as a problem, so I have no way of knowing if the '--with's are working.)
4 I tried to follow the instructions at http://ggkarman.de/tech/building-sox-with-mp3-support-on-osx/ I'm not 100% sure I'm downloading the right tarballs, but when I tried to compile the sox part with --with-mad --with-lame it tells me can't find libmad, and I haven't done enough with compiling to know what I'm doing wrong.

So, the solution turned out to be downloading LAME (which besides providing libraries for other programs also has its own commandline tool) and then doing a two step process:
sox wonky.wav -b 16 better.wav
lame better.wav --preset medium better.mp3
(Sox is  much better at reading the wonky wav file, so it still has to be in the loop.)

No comments:

Post a Comment