Lingua-PT-Speaker

 view release on metacpan or  search on metacpan

lib/Lingua/PT/Speaker.pm  view on Meta::CPAN

# say to emacs, I want -*- cperl -*- mode
package Lingua::PT::Speaker;

use strict;

use Lingua::PT::PLN;

use Lingua::PT::Speaker::Numbers;
use Lingua::PT::Speaker::Words2Sampa;
use Lingua::PT::Speaker::Prosody;
use Lingua::PT::Speaker::AdjWords;
use Lingua::PT::Speaker::Specials;

require Exporter;

our @ISA = qw(Exporter AutoLoader);
our @EXPORT = qw(&speak &toPhon);

our $VERSION = "0.12";

use locale;
$ENV{LC_LANG}='PT_pt';

$INC{'Lingua/PT/Speaker.pm'} =~ m!/Speaker\.pm$!;
our $ptpho = "$`/Speaker/ptpho";
our $naoacentuadas = "$`/Speaker/nao_acentuadas";

our $debug;

BEGIN{ $debug = 0;}

our $vg = '[6AEIOUaeiouyw@]';
our $con = '[BCDFGHJKLMNPQRSTVWXYZÇbcdfghjklmnpqrstvxzç]';


=head1 NAME

Lingua::PT::Speaker - perl extension text to speech of Portuguese text

=head1 SYNOPSIS

  use Lingua::PT::Speaker;

  $pt1 = '/usr/lib/mbrola/pt1/pt1';

  Lingua::PT::speaker::debug() if $debug;

  my $tmp="/tmp/_$$";

  $/="" if  $l;
  while($line = <>){
     speak({output => "$tmp.pho"}, $line);
     system("mbrola -t $t $pt1 $tmp.pho $tmp.wav; play $tmp.wav"); 
  }

=head1 DESCRIPTION


=head2 EXPORT


=head1 AUTHOR

J.Joao Almeida, jj@di.uminho.pt

Alberto Simões, albie@alfarrabio.di.uminho.pt

=head1 SEE ALSO

Lingua::PT::PLN

mbrola

mbrola/pt1

perl(1).

=cut      

sub debug {
  $debug = ! $debug ; 
}

sub speak {
  my $text = shift;
  my %opt = (output => "_.pho");

  if(ref($text) eq "HASH"){
     %opt= (%opt, %$text);
     $text = shift;
  }

  $text.="." unless $text=~/[!.?]$/;

  our $dic = carregaDicionario($ptpho);
  our $no_accented = chargeNoAccented($naoacentuadas);

  open PHO, "> $opt{output}";

  $text =~ s{_\((.*?)\)_}{Lingua::PT::Speaker::Numbers::math($1)}ge;
    print STDERR "1 {{$text}}\n" if $debug ;
  $text =~ s{(\w+\@(\w+\.)+\w+)}{Lingua::PT::Speaker::Numbers::email($1)}ge;
    print STDERR "2\n" if $debug ;
  $text =~ s{(((((ht|f)tp://)|(www\.))(\w+\.)+\w+)(/\w+)*)}{Lingua::PT::Speaker::Numbers::email($1)}ge;
    print STDERR "3\n" if $debug ;
  $text =~ s{(\d+[ºª])}{Lingua::PT::Speaker::Numbers::ordinais($1)}ge;
    print STDERR "4\n" if $debug ;
  $text =~ s{(\d+(\.\d+)?)}{Lingua::PT::Speaker::Numbers::number($1)}ge;
    print STDERR "5\n" if $debug ;
  $text =~ s{\b([B-DF-HJ-NP-TV-Z]{1,7})\b}{Lingua::PT::Speaker::Numbers::sigla($1)}ge;



( run in 2.047 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )