#!/usr/bin/perl -s ### NOT WITH -w #use locale; my $pt1 = '##PT1##'; #/usr/lib/mbrola/pt1/pt1'; # use vars qw{ $debug $raw $esd $t $l $q $show $notags}; our ($debug, $raw, $esd, $play, $sndplay, $t, $l, $k, $q, $show, $notags, $cebolinha, $porto, $viseu, $spain, $lamego, $sotaque, $aplay, $wav, $latin1, $help, $h); my $default = '##PLAYER##'; # play... $default = "play" if $default =~ m!##player##!i; # Hack O:-) $default = "raw" if $raw; $default = "sndplay" if $sndplay; $default = "esd" if $esd; $default = "aplay" if $aplay; use Lingua::PT::Speaker; use utf8::all $t = $t || 1.5; Lingua::PT::Speaker::debug() if $debug; if ($h || $help) { print " Usage:\n"; print "\t-play use play to output sound\n"; print "\t-aplay use aplay to output sound (alsa)\n"; print "\t-raw use rawplay to output sound\n"; print "\t-esd use esound daemon to output sound\n"; print "\t-latin1 latin1\n"; print "\t-sndplay use sndplay to output sound\n"; print "\t-h(elp) this help screen\n"; print "\t-notags remove HTML-like tags from text\n"; print "\t-wav=file.wav output sound to this specific wav file\n"; print "\t-q|-k keep temporary wav file\n"; print "\n"; print "\t-spain\n"; print "\t-viseu\n"; print "\t-porto\n"; print "\t-lamego\n"; print "\t-cebolinha\n"; print "\t-sotaque cebolinha,porto list of accents\n"; exit; } my $tmp="/tmp/_$$"; $/="" if $l; if(@ARGV && $ARGV[0] =~ /\.pho$/) { if($wav){ `##MBROLA## -t $t $pt1 $ARGV[0] $wav`; ## FIX ME -- use global player ## `$default $wav`; } else{ `##MBROLA## -t $t $pt1 $ARGV[0] $tmp.wav`; ## FIX ME -- use global player `$default $tmp.wav`; unlink( "$tmp.wav") unless($q); } exit 0; } if($latin1){binmode(STDIN,":encoding(ISO-8859-1)")}; my @sotaque= split(",",$sotaque) || (); push @sotaque, 'cebolinha' if ($cebolinha); push @sotaque, 'porto' if ($porto); push @sotaque, 'lamego' if ($lamego); push @sotaque, 'spain' if ($spain); push @sotaque, 'viseu' if ($viseu); ## my $pho_out=""; while($line = <>) { $line =~ s/[«»"']//g; $line =~ s![\[\]]!,!g; $line =~ s!([^_])\(!$1,!g; $line =~ s!\)([^_])!,$1!g; $line =~ s!\<.*?\>!!g if $notags; $line =~ s!_{3,}! barra horizontal !g; # $line =~ s!\~! til !g; # $line =~ s!=! igual !g; # $line =~ s!\*! asterisco !g; # $line =~ s!\! maior !g; # $line =~ s!\|! barra !g; # $line =~ s!\#! cardinal !g; # $line =~ s! ! . nova página. !g; next unless $line =~ /\w/; print $line if $show; speak({special => \@sotaque, output => "$tmp.pho"}, $line); if ($pho) { my $fon; open(F,"<","$tmp.pho") ; while($fon=){ print $fon } close F; unlink ( "$tmp.pho" ) unless $q; } elsif ($wav) { `##MBROLA## -t $t $pt1 $tmp.pho $wav`; unlink ( "$tmp.pho" ) unless $q; } elsif ($default =~ m!rawplay$!) { `##MBROLA## -t $t $pt1 $tmp.pho -.raw|rawplay`; unlink( "$tmp.pho") unless $q; } elsif ($default =~ m!\baplay$!) { `##MBROLA## -t $t $pt1 $tmp.pho -.raw|aplay -f S16_LE -r 22050 -c 1 -q -t raw`; unlink( "$tmp.pho") unless $q; } elsif ($default =~ m!\b(esdplay|sndplay|aplay|play)$!) { `##MBROLA## -t $t $pt1 $tmp.pho $tmp.wav`; `$default $tmp.wav`; unlink( "$tmp.pho","$tmp.wav") unless $q; } else { die("No player found...\n") } } __END__ =encoding UTF-8 =head1 NAME pt-speak - perl script to read texts using Mbrola and Lingua::PT::Speaker =head1 SYNOPSIS pt-speak [options] (text|file.pho|file.wav)* options: -debug show the intermediate TTS results -l paragraph is a empty line (def: \n) -t=0.9 read faster (def=1.5) -notags dont read html like tags -raw use raw player -esd use esd sound -aplay use aplay (ALSA mixer) -latin1 encoding = latin1 (default = utf8) -q|-k dont remove /tmp/... temp. files -show show the current line (for debug) -sotaque=cebolinha,porto -porto to ask for Porto's sotaque -wav=out.wav to create a wave file =head1 DESCRIPTION Translates a Portuguese text to a .wav file and says it using Mbrola speech synthesizer. =head1 AUTHOR J.Joao Almeida, jj@di.uminho.pt Alberto Simões, ambs@cpan.org =head1 SEE ALSO Lingua::PT::Speaker(3). perl(1). mbrola(1). =cut