#!/usr/bin/perl -w
srand(time ^ $$);

my $text=join(" ",@ARGV);
if ($text){
	sentence($text);
} else{
while (<>){ 
	$a .=$_;
}
sentence($a);
}
sub sentence{
my $text =shift;
#$text =~ s/[\s|\n]/+/g;
$text =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;

my @voices=('man','child','woman','coffee','bigman','raspy','ridiculous');
my @langs=('german','english','spanish');
my $voice=$voices[rand(@voices)];
my $lang=$langs[rand(@langs)];
my $audio="au";
my $tts='http://wwwtts.research.bell-labs.com/cgi-user/tts/voicestts-nj?';
$tts .= 'voice='.$voice;
$tts .= "&text=$text";
$tts .= "&audio=.au";
$tts .= "&language=$lang";
print "$tts\n";
my $au = `webget '$tts'`;
$file="/fire/tmp/bsaytt";
#open (DEV, ">>$file")  || die "Can't open $file $!" ;
open (DEV, ">>$file");
print DEV $au;
close (DEV);
`export HOME=~jip && (esdplay $file&)`;
`rm -f $file`;
}
#webget 'http://wwwtts.research.bell-labs.com/cgi-user/tts/voicestts-nj?voice=man&text='$i'&audio=.au' > /dev/audio
