linux poison RSS
linux poison Email

Script to convert .wav to .mp3

Put all your .wav files (that you want to convert) into a folder and execute the following script from within this folder, make sure to make this script executable (chmod 777 wav2mp3.sh)

#!/bin/sh
# name of this script: wav2mp3.sh
# wav to mp3

for i in *.wav; do
 if [ -e "$i" ]; then
   file=`basename "$i" .wav`
   lame -h -b 192 "$i" "$file.mp3"
 fi
done
Dependencies
faad2 and lame




25 comments:

Hungry Hamster said...

As is so often the case, here I am looking for a solution and I find it. The Linux world is the 'only' world to inhabit :)

Thank you and thank you to those who have influenced you.

Great work and many thanks.

Regards,

Patrick

Anonymous said...

I found this to be very helpful. All the search results I got for converting WAV files to MP3 in Linux were way too complicated -- I knew there'd be something similar. Thanks a bunch!

Anonymous said...

Very nice!

Anonymous said...

Awesome ... from googling to implementation, 2 minutes.

THANKS

rmj said...

thanks for the script
rmj

Anonymous said...

Thank you! This script really does the job. Works perfectly on my fedora 14-system.
Cheers, Tove

Oneadvent said...

Would change it to allow for WAV as well as wav.

skrymer said...

Works like a charm... Cheers and keep up the good scripting :)

Anonymous said...

chmod 777 is a evil, dont use!
use chmod +x and read the manual (man chmod)

RobertTue said...

Thanks a lot mate, always nice to find precisely what you are looking for in under a minute.

Author said...

Online tool for conversion in AS3

convert mp3 to wav

Bless said...

Excellent. Excellent. Now that is just excellent. You know, seeing the script got me an idea - I am going to expand the script to rip all my audio CDs the moment I insert them, cos I do that a lot - and add it as an autoplay option.

Not entirely sure yet how that is done, the autoplay part, but it's worth finding out. Again, thanks for an amazingly neat script.

michkhoo said...

It works great, i had to install lame (small) though. Thanx

Anonymous said...

Should the line be
if [ -f "$i" ]; then

as -e tests if the file exists and-f tests if the file exists and is also a real file rather than a device, directory, block etc., ?

Anonymous said...

on UBUNTU use RIPPER X to convert all audio files ^-^
to easy

Veljo said...

Cheers dude, works like a charm!

Anonymous said...

exactly what I was looking for, cheers!

Anonymous said...

Cheers !

Author said...

Thanks for the post..
Here is online free mp3 to wav converter
convert mp3 to wav

InsaneOcrabs said...

When I execute this script (with some slight modifications) as written above...

for i in *wav; do
if [ -f "$i" ]; then
file='basename "$i" .wav'
lame -h -b 320 "$i" "$Output/$file.mp3"
fi
done

the output writes all files in the directory as:
basename"$i".wav.mp3

Because each file is written as basename"$i".wav.mp3, the result is that only 1 file is written to the output directory (the preceding file is overwritten every time).

I can amend the script slightly to remove the "basename" command:

for i in *wav; do
if [ -f "$i" ]; then
file="$i"
lame -h -b 320 "$i" "$Output/$file.mp3"
fi
done

to get a slightly better result:

FileName.wav.mp3

But the problem is that now I'm stuck with 2 extensions. Surely I'm not the only one who has encountered this problem! If anyone has run into this problem and found their way around it, would you please tell me how I can edit this script to remove .wav and replace with .mp3 upon conversion? Also, if I've done something wrong, please notify me.

Thanks in advance for your help.

Azare Puasa said...

Worked for me. Simple & effective. Thanks for the post.

Anonymous said...

Thanks for repositories, thanks for shell scripts, and thanks for awesome people like you who post exactly what we were looking for--no need to install bloatware.

Chris Morris said...

very helpful. thanks.

Post a Comment

Related Posts with Thumbnails