LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2006, 11:46 PM   #1
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 44
wav2mp3


I found a good script that converts wav files into mp3s. But I would like to know how to modify it so that it does each wav file one by one in a directory until they are all done. Right now I am having to copy each wav file to a new directory and running the script. I will post the script below and if someone could help I would appreciate it.

Code:
#!/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 96 "$i" "$out.mp3"
    lame -h -b 96 "$i" "${i%.wav}.mp3"
done
Thanks!

j
 
Old 10-04-2006, 12:43 AM   #2
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Rep: Reputation: 30
You just about had it figured out. This seems to work for me:

Code:
#!/bin/bash -
# wav2mp3

FILES=`ls *.wav`

for i in $FILES; do
   OUT=`echo $i | sed -e 's/.wav//'`
   lame -h -b 96 $i $OUT.mp3
done
 
Old 10-04-2006, 12:50 AM   #3
jens
Senior Member
 
Registered: May 2004
Location: Belgium
Distribution: Debian, Slackware, Fedora
Posts: 1,463

Rep: Reputation: 299Reputation: 299Reputation: 299
"lame -h -b 96" will not give you good quality though.
Consider using a higher bitrate.
 
Old 10-04-2006, 01:02 AM   #4
pda_h4x0r
Member
 
Registered: Feb 2006
Location: somewhere in cyberspace
Distribution: Debian, Familiar
Posts: 380

Rep: Reputation: 31
Try this:

Code:
#!/bin/bash
#
# wav2mp3
#
# The directory to export .mp3 files to is passed as argument 1
# The script should be invoked as wav2mp3 new_dir/
# If there is no argument, a default value is used.
# If the directory doesn't exist, then it is created if the user has enough permissions
#
EXPORT_DIR=
if [ $# -eq 0 ]; then
EXPORT_DIR="wav2mp3_out"
else
EXPORT_DIR="$1"
fi

if ! [ -d $EXPORT_DIR ]; then
mkdir -p $EXPORT_DIR
fi

# now EXPORT_DIR holds the directory to which to export the new files

for i in *.wav; do
    lame -h -b 96 "$i" "$EXPORT_DIR/$i.mp3"
done

Last edited by pda_h4x0r; 10-04-2006 at 01:03 AM.
 
Old 10-04-2006, 01:10 AM   #5
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Original Poster
Rep: Reputation: 44
Thanks Pete1234 that worked perfectly!
 
Old 10-04-2006, 01:12 AM   #6
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Rep: Reputation: 30
You're welcome.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Good wav2mp3 encoder for linux? DarkXtar Linux - Software 4 03-31-2009 04:31 PM
lame wav2mp3 encoding help Cinematography Linux - Software 3 11-06-2005 02:17 PM
Wav2mp3 freaker2k5 Linux - Software 4 08-21-2004 03:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:52 PM.

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
Open Source Consulting | Domain Registration