LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   using mpg123 to convert .mp3 to .wav files (https://www.linuxquestions.org/questions/linux-software-2/using-mpg123-to-convert-mp3-to-wav-files-332570/)

cddesjar 06-11-2005 06:12 PM

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

kencaz 06-11-2005 08:10 PM

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 ":o: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

rmutt 06-29-2005 11:33 AM

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++;
}


cddesjar 06-29-2005 11:51 AM

#!/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

homey 06-29-2005 12:12 PM

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`"

rmutt 06-29-2005 02:51 PM

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.

andrelopes 02-11-2012 03:15 PM

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

raywood 06-26-2018 11:28 PM

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

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


All times are GMT -5. The time now is 04:21 PM.