How to add a mp3 handler to sox?

99

21

I want to play music in the terminal with sox.

# install sox/lame
sudo apt-get install sox
sudo apt-get install lame

# play music
play music.mp3
# play FAIL formats: no handler for file extension `mp3'

# mp3 -> wav
lame --decode music.mp3 music.wav

# play music
play music.wav

~ $ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"

~ $ sox --version
sox: SoX v14.3.2

The size of music.wav is +10 times larger than music.mp3.
I don't want to convert all *.mp3 to *.wav.
Is it possible to add mp3-handler to sox?

kev

Posted 2012-05-06T07:42:23.290

Reputation: 9 972

2

instead of the present accepted answer (lame/pipe), the correct/simplest answer is install libsox-fmt-all http://superuser.com/a/421168/73961

– michael – 2016-06-24T04:33:28.727

what linux distro are you on... and what version of the distro and sox are you running... also running sox -h reports codecs supported by the program... please check if mp3 is supported therein... – user1055604 – 2012-05-06T07:59:16.497

Answers

5

Pipe?

lame --decode music.mp3 - | play -

Won't leave any trace.

eepp

Posted 2012-05-06T07:42:23.290

Reputation: 214

11The question was about a sox handler. This is definitely not sox :) – Elektordi – 2017-08-19T09:00:01.613

you can also pipe into sox – Scott – 2018-11-07T06:45:43.673

238

Install libsox-fmt-mp3:

sudo apt-get install libsox-fmt-mp3

kev

Posted 2012-05-06T07:42:23.290

Reputation: 9 972

7+1, this should be the accepted answer because it allows for other things beyond playing as well, for example conversion (e.g. sox input.wav output.mp3 won't work without this package) – pascalhein – 2014-07-10T14:48:21.587

3after installing libsox-fmt-mp3 and running it i get a : sox WARN mp3-util: MAD lost sync – kroe – 2015-08-24T23:32:03.060

@zrajm indeed I had no problems here on Linux Mint, this answer did the trick for me – gilbertohasnofb – 2017-01-12T15:45:57.127

on Debian there's the libsox-fmt-all package which gives you more too! I also did an apt-get purge sox and apt-get install sox afterward just in case, but I don't know if it was actually necessary. Worked fine. – bchurchill – 2018-05-24T00:59:38.960

This works great in ubuntu 18.04 – EyesBear – 2019-07-04T08:26:13.207

I found I also needed to upgrade sox after that; so it doesn't hurt to add "sox" to the above command. – jcomeau_ictx – 2012-09-12T05:44:27.640

This does not work for me. Even after aptitude reinstall sox I still get a SoX was compiled without MP3 encoding support when I try to run sox afterwards. (Though admittedly I'm still running Lucid, this might work better on a more modern Ubuntu.) – zrajm – 2013-10-23T08:06:27.567

12@kev, you should select this as the accepted answer. Also, there is a libsox-fmt-all package that installs the mp3 format, as well as all other available formats. – naught101 – 2014-01-11T23:23:38.313