Saturday, May 15, 2010

Fixing SoX — Again

June 15, 2011: In Ubuntu 11.04, you can add MP3 support to the Ubuntu supplied version of SoX with the libsox-fmt-mp3 package, so all of this is now unnecessary.

For as long as I remember in my Linux career I've been using Sound eXchange (SoX) to convert audio files from one format to another — in particular, converting to MP3 format so that I could play them on my audio player. As I've noted before, this isn't an easy task. Distributions are understandably reluctant to deal with the licensing and patent issues encumbering MP3 files and so let you figure it out for yourself.

The following seems to be the easiest way to do it. I got the basic process from Inverted Egg, but I'm not going to convert put everything into a .deb file, since it will just get rewritten with the next update.

Here we go:

  1. Download the SoX source tarball. It doesn't matter where you put it, we'll assume it goes to /home/yourname/Downloads.
  2. Open a terminal window and become root:
    $ sudo -i
    You'll get prompted for the password.
  3. Go to a useful directory to unload the source:
    # cd /usr/local/src
  4. Unpack the tarball. Note that the version name will occasionally change:
    # tar xvzf /home/yourname/Downloads/sox-14.3.1.tar.gz
  5. Load Ubuntu's version of SoX into the system, if it's not there already, along with the lame library and header files, which are responsible for mp3 processing:
    # apt-get install sox liblame0 liblame-dev
  6. Find all the packages that Ubuntu's SoX needed to compile, and install those you haven't installed already:
    # apt-get source sox
    That's why you needed to install Ubuntu's SoX in the first place.
  7. Now do the usual installation stuff:
    # cd sox-14.3.1
    # ./configure
    # make
    # make install
  8. Your new version of SoX is in /usr/local/bin/sox. Make sure it works, i.e. it converts files to mp3, and then delete Ubuntu's version of SoX:
    # apt-get purge sox

And you're done. Of course, every once in a while you're going to go back and look for updates, right?


David Malouf -- said...

FINALLY! A post that works for me!

Thank you so much for the effort of figuring out how to make this work and then posting your labor. So much appreciated... just upgraded/migrated to Ubuntu 10.04 and forgot (until recently) how much of a headache the sox + mp3 situation is!

David in Seattle

Anonymous said...

Thank god. I have been looking for this forever. By the way, I had to do the following:

apt-get install sox libmp3lame0 libmp3lame-dev

instead of

apt-get install sox liblame0 liblame-dev

because the second are outdated or something.