How to add a mp3 handler to sox?

107,655

Solution 1

Pipe?

lame --decode music.mp3 - | play -

Won't leave any trace.

Solution 2

Install libsox-fmt-mp3:

sudo apt-get install libsox-fmt-mp3
Share:
107,655

Related videos on Youtube

kev
Author by

kev

Updated on September 18, 2022

Comments

  • kev
    kev almost 2 years

    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?

    • user1055604
      user1055604 about 12 years
      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...
    • michael
      michael about 8 years
      instead of the present accepted answer (lame/pipe), the correct/simplest answer is install libsox-fmt-all superuser.com/a/421168/73961
  • jcomeau_ictx
    jcomeau_ictx almost 12 years
    I found I also needed to upgrade sox after that; so it doesn't hurt to add "sox" to the above command.
  • zrajm
    zrajm over 10 years
    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.)
  • naught101
    naught101 over 10 years
    @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.
  • pascalhein
    pascalhein almost 10 years
    +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)
  • kroe
    kroe almost 9 years
    after installing libsox-fmt-mp3 and running it i get a : sox WARN mp3-util: MAD lost sync
  • gilbertohasnofb
    gilbertohasnofb over 7 years
    @zrajm indeed I had no problems here on Linux Mint, this answer did the trick for me
  • Elektordi
    Elektordi almost 7 years
    The question was about a sox handler. This is definitely not sox :)
  • bchurchill
    bchurchill about 6 years
    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.
  • Scott
    Scott over 5 years
    you can also pipe into sox
  • EyesBear
    EyesBear about 5 years
    This works great in ubuntu 18.04
  • eepp
    eepp almost 4 years
    @Elektordi The play command is SoX. It's basically sox -d. Like ffmpeg vs. ffplay.
  • Elektordi
    Elektordi almost 4 years
    Sorry, I didn't know that... My bad... :/
  • xorinzor
    xorinzor about 2 years
    Works perfectly for me on Ubuntu 22.10