Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 30 Sep 2014, 06:00
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Converting .wav to .mp3
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [18 Posts]   Goto page: 1, 2 Next
Author Message
gary101


Joined: 08 Oct 2006
Posts: 539
Location: Boston, Lincs. UK

PostPosted: Sun 09 Dec 2007, 09:55    Post subject:  Converting .wav to .mp3
Subject description: A little script
 

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
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11079
Location: Arizona USA

PostPosted: Sun 09 Dec 2007, 11:31    Post subject:  

Why go to all that work when you could just use Puppy's Pawdioconverter. Laughing (In Menu > Multimedia)
Back to top
View user's profile Send private message 
Pizzasgood


Joined: 04 May 2005
Posts: 6270
Location: Knoxville, TN, USA

PostPosted: Sun 09 Dec 2007, 12:45    Post subject:  

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. Rolling Eyes

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).

_________________
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

Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 11109
Location: The Peoples Republic of California

PostPosted: Sun 09 Dec 2007, 21:39    Post subject:  

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.
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 09 Dec 2007, 22:43    Post subject:  

Quote:
for i in *.wav;do


this will not read files with spaces in the filename, like collections you created in Windows.

For this reason it is recommended, to do this instead:

Code:
ls *.wav | while read i;do

Then it works.
Mark
Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 11109
Location: The Peoples Republic of California

PostPosted: Sun 09 Dec 2007, 22:58    Post subject:  

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
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 09 Dec 2007, 23:07    Post subject:  

hm, maybe it was fixed in newer versions of bash.
Until maybe 1 year ago that was an often reported request in my german Linuxboard.
I did not try the "for i" yet in Puppy, as I always used " | while" since then.

Mark
Back to top
View user's profile Send private message Visit poster's website 
Pizzasgood


Joined: 04 May 2005
Posts: 6270
Location: Knoxville, TN, USA

PostPosted: Sun 09 Dec 2007, 23:48    Post subject:  

So long as you remember to use "$i" rather than $i, all will be well.
_________________
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

Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 11109
Location: The Peoples Republic of California

PostPosted: Mon 10 Dec 2007, 02:28    Post subject:  

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:

Code:
#!/bin/sh
# for batch decoding mp3 files to wav format.
for i in *.mp3
do lame --decode "$i" "${i%.mp3}.wav"
done


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
Back to top
View user's profile Send private message 
gary101


Joined: 08 Oct 2006
Posts: 539
Location: Boston, Lincs. UK

PostPosted: Mon 10 Dec 2007, 03:10    Post subject:  

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
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11109
Location: The Peoples Republic of California

PostPosted: Mon 10 Dec 2007, 03:51    Post subject:  

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

Code:
#!/bin/sh
for f in *; do
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[a-z]' '[A-Z]'`
mv "$f" "$g"
done


The opposite script I call lowerfn
Code:

#!/bin/sh
for f in *; do
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
mv "$f" "$g"
done


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.
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11079
Location: Arizona USA

PostPosted: Mon 10 Dec 2007, 16:14    Post subject:  

What would the script be for convering .wav to .mp3 at 32kbps mono?
Back to top
View user's profile Send private message 
gary101


Joined: 08 Oct 2006
Posts: 539
Location: Boston, Lincs. UK

PostPosted: Mon 10 Dec 2007, 16:40    Post subject:  

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
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11079
Location: Arizona USA

PostPosted: Mon 10 Dec 2007, 16:48    Post subject:  

Thanks, I hope I can find the time to try it out soon. Smile
Back to top
View user's profile Send private message 
gary101


Joined: 08 Oct 2006
Posts: 539
Location: Boston, Lincs. UK

PostPosted: Mon 10 Dec 2007, 17:38    Post subject:  

tested it out and it seems to produce the desired mp3 type, 32kbs mono

#!/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 32 -m m "$i" "${i%.wav}.mp3"
done

Gary
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [18 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0856s ][ Queries: 11 (0.0045s) ][ GZIP on ]