≡ Menu

Linux Convert an MP3 File to WAV Format

How do I convert an MP3 file to WAV format under Linux using a shell prompt?

There are plenty of tools that to convert an MP3 file into WAV format. I recommend mpg321 which is a free command-line mp3 player, which uses the mad audio decoding library.

Install mpg321 or mpg123

Type the following command under Debian / Ubuntu Linux, enter:

sudo apt-get install mpg321

OR

sudo apt-get install mpg123

I recommend using mpg123 as it is updated frequently.

Install mpg123 under CentOS / RHEL / Fedora Linux

Turn on rpmforge repo and type the following command:

yum install mpg123

Convert an MP3 to WAV

The -w option will convert an .mp3 file to .wav file. The syntax is:

mpg123 -w output.wav input.mp3

OR

mpg321 -w output.wav input.mp3

A Sample Shell Script Helper Function

Add the following to your ~/.bashrc startup file (tested with bash v3.x+):

mp3towav(){
	[[ $# -eq 0 ]] && { echo "mp3wav mp3file"; exit 1; }
	for i in "$@"
	do
		# create .wav file name
		local out="${i%/*}.wav"
		[[ -f "$i" ]] && { echo -n "Processing ${i}..."; mpg123 -w "${out}" "$i" &>/dev/null  && echo "done." || echo "failed."; }
	done
}

Use it as follows:

mp3towav *.mp3
mp3towav "this is a test.mp3"
ls *.wav
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 12 comments… add one }

  • Metalx1000 November 3, 2009, 11:35 pm

    Sorry, I meant:
    ffmpeg -i input.mp3 output.wav

  • nixCraft November 4, 2009, 5:26 am

    @Metalx1000, nice, I’ve deleted your old post and kept only correct one.

  • sanjay November 5, 2009, 5:59 am

    Hi,

    Is there any tool/command in Fedora to convert mp4 files to avi ?
    Or above command will also work for mp4 file.

    Thanks,
    Sanjay

    • nixCraft November 5, 2009, 6:16 am

      Command line tools:

      1. mencoder
      2. ffmpeg

      Gui tools:

      1. avidemux
  • gemuet November 5, 2009, 8:07 am

    is there a tool tool to convert .wmv/wma to mp3/mp4 or any other format which totem can easily play?

  • yoander (sedlav) November 5, 2009, 3:41 pm

    Another gui tool SoundConverter

  • gemuet November 5, 2009, 4:57 pm

    Thanks man.
    I appreciate.

  • Metalx1000 November 5, 2009, 7:24 pm

    Thanks Vivek Gite.

    @gemuet
    ffmpeg -i input.wmv output.mp4
    That will convert the wmv to mp4 with default settings, which may not be the best quality.
    For more option on converting to mp4 with ffmpeg check out this post:
    http://www.modmymoto.com/forums/showthread.php?t=304281

  • gemuet November 6, 2009, 8:08 am

    I appreciate your help man.

  • Jesper January 2, 2012, 4:48 pm

    Very nice – except you cant SIGHUP the script :)

  • Romanenko Bogdan January 25, 2013, 6:02 pm

    Thank’s. Use your article to convert mp3 to wav.

  • Roland August 27, 2014, 2:45 pm

    Don’t put ‘exit’ in a bash function! I ran ‘mp3towav’ with no options, and my terminal window vanished.

Leave a Comment