#!/usr/bin/env perl

use strict;

my $lame = '/usr/local/bin/lame';# PATH to lame encoder

my $esc = ' &"\'';

print "\n(c) 2006, MiF, lame wrapper\n\n";
my @wavs = glob "*.wav";

if (! -x $lame)
{
	print "install lame first\n";
	exit(1);
}

my $cnt = 0;
my $len = scalar(@wavs);

if (!$len)
{
	print "No WAVs found in currend directory\n";
	exit(2);
}

foreach my $wav (@wavs)
{
	$cnt++;
	$wav =~ s/([$esc])/\\$1/gos;
	my $mp3 = $wav;
	$mp3 =~ s/wav$/mp3/so;
	print "=== Converting [$cnt from $len]: $wav to $mp3 ===\n\n";
	system("$lame $wav $mp3");
}
