LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 12-25-2004, 02:36 PM   #1
Vincent_Vega
Member
 
Registered: Nov 2003
Location: Jacksonville, FL
Distribution: Slackware & Arch
Posts: 825

Rep: Reputation: 31
Need help writing a mp3->wav script...


I'm trying to convert a directory full of mp3s into wavs but all I'm able to do is one at a time, specifying each new file name and that takes forever! Can someone tell me a script, or even just a loop command, that will go through the .mp3 files, send them to mpg123 and output the same filename with the .wav extension??
I could go researching to figure it out, I'm sure it's not too hard, but I know lots of people around here have know this like the back of their hand.

Thanks and Merry Christmas!
 
Old 12-25-2004, 04:53 PM   #2
ivanatora
Member
 
Registered: Sep 2003
Location: Bulgaria
Distribution: Ubuntu 9.10, FreeBSD 7.2
Posts: 459

Rep: Reputation: 31
for line in `ls somedir/`
do
mp3toWAV $line
done
Mybe something like that. How do you plan to convert mp3->wav?
If your purpose is to write audio CD, k3b is very good at doing all jobs in one time (converting and writing on the fly).
 
Old 12-26-2004, 01:56 AM   #3
Vincent_Vega
Member
 
Registered: Nov 2003
Location: Jacksonville, FL
Distribution: Slackware & Arch
Posts: 825

Original Poster
Rep: Reputation: 31
I can do what you said but that won't convert like I was hoping to. What I have been doing, one file at a time, is this:
for i in `ls somedir`
do
mpg123 -w file.wav file.mp3
done

That converts like I want but I have to manually enter in the new filename with the .wav extension. I want to do something like this:
for i in `ls somedir`
do
replace the mp3 with wav
mpg123 -w new.wav old.mp3
done

See what I'm getting at?
 
Old 12-26-2004, 01:25 PM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
If you only need to change the extension of all the mp3 files in a single directory, you could use filename substitution.

for mp3file in *.mp3
do
mpg123 -w "${mp3file}" "${mp3file%.mp3}.wav"
done

This will fail if there are no *.mp3 files in the directory, because $mp3file will expand to 'mp3file' but there is a bash option that will expand the variable to null in such a case. Also, the double quotes are necessary in the cases where the filename contains a whitespace character.
The '%.mp3' part removes the trailing .mp3 characters from the filename. If one of the files is called 'MySong.mp3', the line for that iteration of the loop will be:
mpg123 -w MySong.mp3 MySong.wav

For more details you may which to read the 'info bash' manual.

Last edited by jschiwal; 12-26-2004 at 01:28 PM.
 
Old 12-26-2004, 03:52 PM   #5
Vincent_Vega
Member
 
Registered: Nov 2003
Location: Jacksonville, FL
Distribution: Slackware & Arch
Posts: 825

Original Poster
Rep: Reputation: 31
That looks like it's just what I wanted. Thanks for the help!! I'll give it a try tonight and let you know how it works for me.
 
Old 12-27-2004, 12:52 AM   #6
Vincent_Vega
Member
 
Registered: Nov 2003
Location: Jacksonville, FL
Distribution: Slackware & Arch
Posts: 825

Original Poster
Rep: Reputation: 31
Thanks jschiwal, that worked perfectly! I'm going to have to learn some more about the whole scripting thing.
 
Old 12-29-2004, 10:16 PM   #7
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
One book I would recommend is 'The UNIX Programming Environment' by Brian Kernighan and Rob Pike. It isn't a bash shell specific book but does a good job in explaining how things are done in Unix.

If you have the texinfo source for bash, you can run the 'tex' command on it to produce a printable version of the 'info bash' manual. Or from the konquer browser or the application launcher in KDE, you can enter 'info:bash' to produce a more readable version of the manual.
 
Old 12-30-2004, 12:10 AM   #8
Vincent_Vega
Member
 
Registered: Nov 2003
Location: Jacksonville, FL
Distribution: Slackware & Arch
Posts: 825

Original Poster
Rep: Reputation: 31
Thanks for that information. I'll look into them and probably grab a copy of the book you suggested.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing a c program in linux which plays an'.wav' file stephenwalter Programming 8 07-09-2005 12:37 AM
ripping cds to mp3 (or wav to mp3) darkleaf Linux - Software 7 04-30-2005 08:23 AM
mp3 vs wav? mary General 48 12-05-2003 08:34 AM
From .wav to .mp3 how-to Harp00 Linux - Newbie 5 10-23-2003 09:33 PM
.wav to .mp3 El Kid Linux - General 8 11-21-2002 11:48 PM


All times are GMT -5. The time now is 08:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration