Converting .wav to .mp3
Converting .wav to .mp3
Hi
I have had a whole bunch of wav files on the computer that I use Beep media player with and this has been fine.
However, recently I needed to play them on my palm TX which doesn't like .wav files - - So off to google!
I found this little script which converts wav to mp3 and does the job just fine. All you have to do is create the script and run it from the folder where your .wavs are and it will convert all wavs in the folder. You can run it from the command line if you want to see what is going on or just click on the script and let it do the job (code below).
Hope someone finds this as useful as I do.
Gary
Create a new script with the contents:
#!/bin/bash
#
# wav2mp3
#
for i in *.wav; do
#out=$(ls $i | sed -e 's/.wav//g')
#out=$(echo $i | sed -e 's/.wav$//')
#lame -h -b 192 "$i" "$out.mp3"
lame -h -b 192 "$i" "${i%.wav}.mp3"
done
I have had a whole bunch of wav files on the computer that I use Beep media player with and this has been fine.
However, recently I needed to play them on my palm TX which doesn't like .wav files - - So off to google!
I found this little script which converts wav to mp3 and does the job just fine. All you have to do is create the script and run it from the folder where your .wavs are and it will convert all wavs in the folder. You can run it from the command line if you want to see what is going on or just click on the script and let it do the job (code below).
Hope someone finds this as useful as I do.
Gary
Create a new script with the contents:
#!/bin/bash
#
# wav2mp3
#
for i in *.wav; do
#out=$(ls $i | sed -e 's/.wav//g')
#out=$(echo $i | sed -e 's/.wav$//')
#lame -h -b 192 "$i" "$out.mp3"
lame -h -b 192 "$i" "${i%.wav}.mp3"
done
- Pizzasgood
- Posts: 6183
- Joined: Wed 04 May 2005, 20:28
- Location: Knoxville, TN, USA
Because it's faster in the end. Open the directory in Rox. Press the backquote/tilde key to open a terminal there. Type wav2mp3 and hit enter.
My process is a little different. I like to normalize things first, so I installed a package called "normalize" that I found somewhere. And I use Ogg, not Mp3, and also make a copy with flac for archival. So I usually type something like this:
for i in *.wav; do normalize "$i"; oggenc "$i"; flac "$i"; done;
Sometimes I write an actual script out of that, so that I can just run that rather than re-typing everything. But I'm usually too lazy, or else I do make the script and then forget about it the next time I need it.
Also, you could modify that script a little so that you could call it like this:
wav2mp3 *.wav
That would allow you to specify which files to convert. If you only wanted to convert certain files, you could type wav2mp3 followed by a space, then select the files in Rox (left-click drag lasso, and remember that middle-click drag lasso works the same as holding [ctrl] with the left-click version). Now middle-click in the terminal to paste the absolute paths of each file (WARNING: you'll have to manually \escape any spaces, or put any path with spaces in "quotes"). Then hit enter.
I don't remember the exact process you'd need to use. It involves using shift to change which parameter is referenced by $1. The Rute Guide explains it, or just google or look through some scripts that take multiple parameters in that way. I've uploaded some things that do it too (including an audio converter similar to yours, but that depends on mplayer to convert just about anything into a wav).
My process is a little different. I like to normalize things first, so I installed a package called "normalize" that I found somewhere. And I use Ogg, not Mp3, and also make a copy with flac for archival. So I usually type something like this:
for i in *.wav; do normalize "$i"; oggenc "$i"; flac "$i"; done;
Sometimes I write an actual script out of that, so that I can just run that rather than re-typing everything. But I'm usually too lazy, or else I do make the script and then forget about it the next time I need it.
Also, you could modify that script a little so that you could call it like this:
wav2mp3 *.wav
That would allow you to specify which files to convert. If you only wanted to convert certain files, you could type wav2mp3 followed by a space, then select the files in Rox (left-click drag lasso, and remember that middle-click drag lasso works the same as holding [ctrl] with the left-click version). Now middle-click in the terminal to paste the absolute paths of each file (WARNING: you'll have to manually \escape any spaces, or put any path with spaces in "quotes"). Then hit enter.
I don't remember the exact process you'd need to use. It involves using shift to change which parameter is referenced by $1. The Rute Guide explains it, or just google or look through some scripts that take multiple parameters in that way. I've uploaded some things that do it too (including an audio converter similar to yours, but that depends on mplayer to convert just about anything into a wav).
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]
[img]http://www.browserloadofcoolness.com/sig.png[/img]
Great little script, does just what its supposed to do. I have had a chance to use it, but have done a little testing by echoing the output. It seems to do three things that are important:
* get rid of the .wav portion of the output file
* handle spaces in input and output files
* allow for easy user defined modification of lame parameters.
------------
Not to mention easy to run.
------------
Here is the echoed output:
lame -h -b 192 test1.wav test1.mp3
lame -h -b 192 test2.wav test2.mp3
lame -h -b 192 test3.wav test3.mp3
lame -h -b 192 test4.wav test4.mp3
lame -h -b 192 test 5.wav test 5.mp3
lame -h -b 192 test 6.wav test 6.mp3
lame -h -b 192 test 7.wav test 7.mp3
Thanks a lot.
* get rid of the .wav portion of the output file
* handle spaces in input and output files
* allow for easy user defined modification of lame parameters.
------------
Not to mention easy to run.
------------
Here is the echoed output:
lame -h -b 192 test1.wav test1.mp3
lame -h -b 192 test2.wav test2.mp3
lame -h -b 192 test3.wav test3.mp3
lame -h -b 192 test4.wav test4.mp3
lame -h -b 192 test 5.wav test 5.mp3
lame -h -b 192 test 6.wav test 6.mp3
lame -h -b 192 test 7.wav test 7.mp3
Thanks a lot.
this will not read files with spaces in the filename, like collections you created in Windows.for i in *.wav;do
For this reason it is recommended, to do this instead:
Code: Select all
ls *.wav | while read i;do
Mark
Mark,
I didn't have any .wav files to work with at present.
I was curious about the handling of spaces, especially because we are likely to encounter them in .wav files.
My test procedure for the spaces was to 'touch' files 5 thru 7 and view the output, by placing echo at the beginning of the lame command line.
In this case the spaces showed in the input files and the output files.
Probably, what I'll do next is find a cd to rip.
Adjust as necessary.
Thanks,
Bruce
I didn't have any .wav files to work with at present.
I was curious about the handling of spaces, especially because we are likely to encounter them in .wav files.
My test procedure for the spaces was to 'touch' files 5 thru 7 and view the output, by placing echo at the beginning of the lame command line.
In this case the spaces showed in the input files and the output files.
Probably, what I'll do next is find a cd to rip.
Adjust as necessary.
Thanks,
Bruce
- Pizzasgood
- Posts: 6183
- Joined: Wed 04 May 2005, 20:28
- Location: Knoxville, TN, USA
Just to make sure the record is straight.
#1 I don't purport or pretend to have bash scripting skills equal to Mark's.
# 2 My preliminary 'echo' tests worked, I decided to try some actual tests. Still not having .wav files to work with I wrote a minimally modified version of wav2mp3 called mp32wav. The purpose being to actually test for real the handling of spaces in the filenames. This is the actual script:
The in-files are mp3 with multiple spaces, the out-files are wav with the same multiple spaces. At the end of the decoding, the only difference in the filenames are the extensions.
============
I guess the net result at this point is we have two simple and useful scripts:
1) for .wav to .mp3 batch conversion using lame
2) for .mp3 to .wav batch conversion using lame
#1 I don't purport or pretend to have bash scripting skills equal to Mark's.
# 2 My preliminary 'echo' tests worked, I decided to try some actual tests. Still not having .wav files to work with I wrote a minimally modified version of wav2mp3 called mp32wav. The purpose being to actually test for real the handling of spaces in the filenames. This is the actual script:
Code: Select all
#!/bin/sh
# for batch decoding mp3 files to wav format.
for i in *.mp3
do lame --decode "$i" "${i%.mp3}.wav"
done
============
I guess the net result at this point is we have two simple and useful scripts:
1) for .wav to .mp3 batch conversion using lame
2) for .mp3 to .wav batch conversion using lame
This seems to have generated more interest than I thought.
Here is the link to the page I found on goole for the script above (I just changed the order of wav and mp3 to convert the other way) which includes stuff like removing spaces, converting to lower case and normalising.
Not that I need to do any of that stuff, but it is handy to know.
http://www.faqs.org/docs/Linux-mini/MP3-CD-Burning.html
Enjoy!
Gary
Here is the link to the page I found on goole for the script above (I just changed the order of wav and mp3 to convert the other way) which includes stuff like removing spaces, converting to lower case and normalising.
Not that I need to do any of that stuff, but it is handy to know.
http://www.faqs.org/docs/Linux-mini/MP3-CD-Burning.html
Enjoy!
Gary
Gary,
Puppy contains spacereplace for purpose of replacing spaces with underscores. Works in current directory and / or in subdirectories.
To initiate help say spacereplace -h or say spacereplace
Caution: the program actually works! Meaning on the whole directory. There is no undo, but one could be written easy enough to replace underscores with spaces.
Here is a script called upperfn, it converts filenames to uppercase in the whole directory
The opposite script I call lowerfn
I didn't write these scripts and don't remember where I picked them up.
-----------------
I think both programs need a little work because they act too effectively, changing all file names in the current directory without a prewarning or confirmation.
The operational difference between these and the ones at the link you posted is they change filenames with spaces in them.
What I want is a program that converts to Capital case.
Thanks again,
Bruce
I had a similar mp32wav program of my own, but it didn't do it in a single command, not even close.
Puppy contains spacereplace for purpose of replacing spaces with underscores. Works in current directory and / or in subdirectories.
To initiate help say spacereplace -h or say spacereplace
Caution: the program actually works! Meaning on the whole directory. There is no undo, but one could be written easy enough to replace underscores with spaces.
Here is a script called upperfn, it converts filenames to uppercase in the whole directory
Code: Select all
#!/bin/sh
for f in *; do
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[a-z]' '[A-Z]'`
mv "$f" "$g"
done
Code: Select all
#!/bin/sh
for f in *; do
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
mv "$f" "$g"
done
-----------------
I think both programs need a little work because they act too effectively, changing all file names in the current directory without a prewarning or confirmation.
The operational difference between these and the ones at the link you posted is they change filenames with spaces in them.
What I want is a program that converts to Capital case.
Thanks again,
Bruce
I had a similar mp32wav program of my own, but it didn't do it in a single command, not even close.
Hi Flash
After looking at the lame man page: http://linux.die.net/man/1/lame
I reckon it would be something like this:
lame -h -b 32 -m m "$i" "${i%.wav}.mp3"
within the loop as specified in previous posting
But I haven't tried it out yet.
Gary
After looking at the lame man page: http://linux.die.net/man/1/lame
I reckon it would be something like this:
lame -h -b 32 -m m "$i" "${i%.wav}.mp3"
within the loop as specified in previous posting
But I haven't tried it out yet.
Gary
Do anyone know where to find a normalize pet-package. This could be great in Pburn when encoding a audio-CD.pizzagood wrote:My process is a little different. I like to normalize things first, so I installed a package called "normalize" that I found somewhere. And I use Ogg, not Mp3, and also make a copy with flac for archival. So I usually type something like this:
for i in *.wav; do normalize "$i"; oggenc "$i"; flac "$i"; done;
Sigmund
- Pizzasgood
- Posts: 6183
- Joined: Wed 04 May 2005, 20:28
- Location: Knoxville, TN, USA
Okay, here's a package of the one I've been using (taken from an rpm):
normalize-0.7.6-2-i386.pet
normalize-0.7.6-2-i386.pet
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]
[img]http://www.browserloadofcoolness.com/sig.png[/img]