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.

ADVERTISEMENTS

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
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
15 comments… add one
  • Metalx1000 Nov 3, 2009 @ 23:35

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

  • 🐧 nixCraft Nov 4, 2009 @ 5:26

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

  • sanjay Nov 5, 2009 @ 5:59

    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 Nov 5, 2009 @ 6:16

      Command line tools:

      1. mencoder
      2. ffmpeg

      Gui tools:

      1. avidemux
  • gemuet Nov 5, 2009 @ 8:07

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

  • yoander (sedlav) Nov 5, 2009 @ 15:41

    Another gui tool SoundConverter

  • gemuet Nov 5, 2009 @ 16:57

    Thanks man.
    I appreciate.

  • Metalx1000 Nov 5, 2009 @ 19:24

    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 Nov 6, 2009 @ 8:08

    I appreciate your help man.

  • Jesper Jan 2, 2012 @ 16:48

    Very nice – except you cant SIGHUP the script :)

  • Romanenko Bogdan Jan 25, 2013 @ 18:02

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

  • Roland Aug 27, 2014 @ 14:45

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

    • Mathieu Apr 15, 2016 @ 7:54

      You didn’t look before hey? Copy/paste is good but one has to make sure to evaluate/understand before using! Enough said, happened to me too hahahahhaha. I solve the “potential issue” by replacing:

      echo “mp3wav mp3file”; exit 1;

      by

      echo “usage: mp3towav filenames”;

  • hezhixiong Jul 7, 2015 @ 9:24

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

  • StephaneAG Nov 8, 2015 @ 16:21

    Hi there, thanks for the ffmpeg quickie, was handy to call the following ;p

    for file in ./*.mp3; do ffmpeg -i "${file}" "${file%.*}.wav"; done;

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.