LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-11-2005, 06:12 PM   #1
cddesjar
Member
 
Registered: Jan 2004
Location: Maine/Minnesota/Alberta
Distribution: Debian Sid
Posts: 125

Rep: Reputation: 15
using mpg123 to convert .mp3 to .wav files


Hi I am running mpg123 to convert my files from .mp3 to .wav
I am doing it this way
mpg123 -w <filename>.wav <filename>.mp3
This works fine for me. But I was wondering if someone knew if there was a way to convert ALL my mp3 files in a directory to wav files with ONE command. something like this...
mpg123 -w *.wav *.mp3
(which i know doesn't work)
My second question is whether or not anyone knows of a GUI that converts mp3 to wav with a drag and a couple clicks of a mouse.
Cheers,
Chris
 
Old 06-11-2005, 08:10 PM   #2
kencaz
Senior Member
 
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
Don't know about mpg123 but I found that using a lame script "mlame" coverts all my .wav to .mp3 automatically:

~/kencaz/./mlame -r -o "-v -V 0 -b 112" *.wav *.mp3

This will convert all file in my current foder from .wav to .mp3. I don't remember where I got the script but it's kinda hard to find so I'll include it here. You'll have to save it to a file then change permissions as usual...

#!/bin/bash
#!/usr/local/bin/bash
############################################################################
#
# Run the LAME encoder on multiple files, with option to delete .wav files
# after encoding. "mlame -h" will give instructions.
#
# Robert Hegemann <Robert.Hegemann@gmx.de>
#
############################################################################

mp3coder="lame"
options="-h -d -m j -b 128"
rmsrc=false

helptext="\
\nThis script runs the LAME mp3 encoder on multiple files: \n\n\
$0 [options] <file 1> ... <file n>\n\
\n\
options:\n\
-h this help text\n\
-r remove files after encoding\n\
-o \"<lame options>\" overrides script default options \"${options}\"\n\
\n\
example:\n\
$0 -r -o \"-v -V 0 -b 112\" a*.wav z*.aif\n\
\n\
"

# process command-line options
# this could be extended to fake the
# commandline interface of the mp3encoder

while getopts ":r" optn; do
case $optn in
o ) options=$OPTARG # replace default options
;;
r ) rmsrc=true
;;
\? ) printf "$helptext"
exit 1
;;
esac
done
shift $(($OPTIND - 1))

# process input-files

for filename in "$@"; do
case $filename in
*[*?]* ) # means shell couldnīt extend *.wav, etc.
echo "warning: no $filename file(s) found"
;;
*[.][wW][aA][vV] )
name=${filename%[.][wW][aA][vV]}
if $mp3coder $options "$filename" "${name}.mp3"
then
if [ $rmsrc = true ]; then
rm -f "$filename"
fi
fi
;;
*[.][aA][iI][fF] )
name=${filename%[.][aA][iI][fF]}
if $mp3coder $options "$filename" "${name}.mp3"
then
if [ $rmsrc = true ]; then
rm -f "$filename"
fi
fi
;;
* )
if $mp3coder $options "$filename" "${filename}.mp3"
then
if [ $rmsrc = true ]; then
rm -f "$filename"
fi
fi
;;
esac
done
 
Old 06-29-2005, 11:33 AM   #3
rmutt
LQ Newbie
 
Registered: Jun 2005
Posts: 2

Rep: Reputation: 0
Re: using mpg123 to convert .mp3 to .wav files

Quote:
Originally posted by cddesjar
Hi I am running mpg123 to convert my files from .mp3 to .wav
I am doing it this way
mpg123 -w <filename>.wav <filename>.mp3
This works fine for me. But I was wondering if someone knew if there was a way to convert ALL my mp3 files in a directory to wav files with ONE command. something like this...
mpg123 -w *.wav *.mp3
(which i know doesn't work)
My second question is whether or not anyone knows of a GUI that converts mp3 to wav with a drag and a couple clicks of a mouse.
Cheers,
Chris
I had this same problem so I wrote a quick and dirty perl script to do this for me. Dump your files to be converted into a temp directory and it will go through them one by one and run the mpg123 command. It renames them to 1, 2, 3, ...ect .WAV files.

Code:
#!/usr/bin/perl

 my $dir = "/change/this/to/your/directory";

 opendir DH, $dir or die "Can't open  $dir: $!";
 $count2=1;
 while  ($name = readdir DH) {
  next unless $name =~ /\.mp3$/;
  $wav="$count2.wav";
   print "$wav\n";
system "mpg123 -w $wav \"$name\"";
  $count2++;
}
 
Old 06-29-2005, 11:51 AM   #4
cddesjar
Member
 
Registered: Jan 2004
Location: Maine/Minnesota/Alberta
Distribution: Debian Sid
Posts: 125

Original Poster
Rep: Reputation: 15
#!/usr/bin/perl

my $dir = "/change/this/to/your/directory";

opendir DH, $dir or die "Can't open $dir: $!";
$count2=1;
while ($name = readdir DH) {
next unless $name =~ /\.mp3$/;
$wav="$count2.wav";
print "$wav\n";
system "mpg123 -w $wav \"$name\"";
$count2++;
}



So I just changed the line
my $dir = "/change/this/to/your/directory";
to my directory where i hold my mp3s but the script didn't work...nothing happened. Any ideas why?

Thanks,
Chris
 
Old 06-29-2005, 12:12 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
This little diddy from my notes should get you going.....
Code:
cd /home/music/directory
for i in *.mp3; do mpg321 -w "`basename "$i" .mp3`".wav "$i"; done
or using lame might look like this...
Code:
cd /home/music/directory
for i in *.mp3; do lame --decode "$i" "`basename "$i" .mp3`".wav; done

This part is in quotes to handle names with spaces in them "`basename "$i" .mp3`"
 
Old 06-29-2005, 02:51 PM   #6
rmutt
LQ Newbie
 
Registered: Jun 2005
Posts: 2

Rep: Reputation: 0
Quote:
Originally posted by cddesjar
#!/usr/bin/perl

my $dir = "/change/this/to/your/directory";

opendir DH, $dir or die "Can't open $dir: $!";
$count2=1;
while ($name = readdir DH) {
next unless $name =~ /\.mp3$/;
$wav="$count2.wav";
print "$wav\n";
system "mpg123 -w $wav \"$name\"";
$count2++;
}



So I just changed the line
my $dir = "/change/this/to/your/directory";
to my directory where i hold my mp3s but the script didn't work...nothing happened. Any ideas why?

Thanks,
Chris
Hard to say. Are they all named ".mp3" ?? if they are named something like blah.MP3 add an "i" to this line: "next unless $name =~/\.mp3$/" so it looks like this:
next unless $name =~/\.mp3$/i. This will ignore case.

Otherwise did it give you some kind of error? I just used the script a few minutes ago as is so I know it works.
 
Old 02-11-2012, 03:15 PM   #7
andrelopes
LQ Newbie
 
Registered: Feb 2012
Posts: 1

Rep: Reputation: Disabled
Script in ruby:

files = Dir.entries(".")

for file in files
if file.include?(".mp3")
file.gsub!(".mp3", "")
system "mpg123 -w '#{file}'.wav '#{file}'.mp3"
end
end

And I know: the post is old, and script is simple as possible
 
Old 06-26-2018, 11:28 PM   #8
raywood
LQ Newbie
 
Registered: May 2009
Posts: 29

Rep: Reputation: 0
For those who aren't scripters, here's a start toward a simple if verbose kludge:

https://raywoodcockslatest.wordpress...xcel-for-batch
 
  


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
i want to convert .wav file into mp3 files in batch mode sparsh Linux - Software 6 11-20-2007 10:53 AM
Convert mp3 to wav trey85stang Linux - Software 5 08-23-2006 09:57 PM
mp3 to wav convert shibainucan SUSE / openSUSE 1 10-22-2004 10:46 AM
mpg123 and mp3 to wav mikkove Linux - Newbie 1 12-26-2003 10:23 AM
mpg123 and mp3 to wav conversion knmwt15000 Linux - Newbie 7 03-24-2003 04:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:42 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
Open Source Consulting | Domain Registration