/[mbrola]/trunk/mbrola.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/mbrola.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4 by dpavlin, Sat Aug 5 12:44:39 2006 UTC revision 5 by dpavlin, Tue Aug 8 15:06:33 2006 UTC
# Line 7  Line 7 
7  use strict;  use strict;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9  use Term::ReadLine;  use Term::ReadLine;
10    use File::Slurp;
 my $term = new Term::ReadLine 'Simple Perl calc';  
 my $prompt = "Pričaj: ";  
 my $OUT = $term->OUT || \*STDOUT;  
   
11    
12  my $letters = {  my $letters = {
13          'a' => [['a'],          'a' => [['a'],
# Line 194  my $silence = { Line 190  my $silence = {
190  };  };
191    
192  my $recovery;  my $recovery;
193  foreach my $df (qw/ bp oo uks/) {  foreach my $df (qw/bp oo uks/) {
194          $recovery->{$df}++;          $recovery->{$df}++;
195  }  }
196    
# Line 216  sub speak_hr { Line 212  sub speak_hr {
212    
213          my $last_c = '';          my $last_c = '';
214    
215          foreach my $i ( 0 .. $#chars ) {          my $i = 0;
216                  my $c = $chars[$i];          while (@chars) {
217                    my $c = shift @chars;
218    
219                  $g .= $c;                  $g .= $c;
220    
221                  if (defined( $phonemes->{$c} )) {                  if (defined( $phonemes->{ lc($c) } )) {
222                          $c = $phonemes->{$c};                          $c = $phonemes->{ lc($c) };
223                  } elsif (defined( $token_to_grapheme->{$c} )) {                  } elsif (defined( $token_to_grapheme->{ lc($c) } )) {
224                          $c = $token_to_grapheme->{$c};                          my $tmp = $token_to_grapheme->{ lc($c) };
225                            if (length($tmp) > 1) {
226                                    my @tmp_c = split(//, $tmp);
227                                    warn "### $c --> $tmp\n";
228                                    $c = shift @tmp_c;
229                                    unshift @chars, ( @tmp_c );
230                            } else {
231                                    $c = $tmp;
232                            }
233                  }                  }
234    
235                  my $d = $durations->{$c} || $silence->{word};                  my $d = $durations->{$c} || $durations->{ lc($c) };
236    
237                    if (! $d) {
238                            next if ($c =~ m/\s/);
239                            warn "### skipped: $c\n";
240                            $c = '_';
241                            $d = $silence->{word};
242                    }
243    
244                  my @dur = ( $d );                  my @dur = ( $d );
245    
# Line 255  sub speak_hr { Line 267  sub speak_hr {
267                          $pho[ $#pho ]->{dur}->[0] += $silence->{word};                          $pho[ $#pho ]->{dur}->[0] += $silence->{word};
268                          push @pho, {                          push @pho, {
269                                  char => '_',                                  char => '_',
270                                  dur => [ $silence->{word} ],                                  dur => [ $silence->{sent} ],
271                          };                          };
272                          $last_c = $c;                          $last_c = $c;
273                          next;                          next;
# Line 301  sub speak_hr { Line 313  sub speak_hr {
313    
314  my $mbrola = './bin/mbrola-linux-i386 ./cr1/cr1';  my $mbrola = './bin/mbrola-linux-i386 ./cr1/cr1';
315    
316  while ( defined ($_ = $term->readline($prompt)) ) {  my $term = new Term::ReadLine 'Mbrola croatian speaker';
317    my $OUT = $term->OUT || \*STDOUT;
318    
319          $term->addhistory($_);  sub play_speak_hr {
320            my $text = shift || return;
321    
322          my ($out,$g,$f) = speak_hr( $_ );          my ($out,$g,$f) = speak_hr( $text );
323    
324          open(my $fh, "| $mbrola - tmp.wav") || die "can't open $mbrola: $!";          open(my $fh, "| $mbrola - tmp.wav") || die "can't open $mbrola: $!";
325    
# Line 318  while ( defined ($_ = $term->readline($p Line 332  while ( defined ($_ = $term->readline($p
332          print $OUT "# $out\n";          print $OUT "# $out\n";
333    
334          system 'play tmp.wav';          system 'play tmp.wav';
335    }
336    
337    
338    if (my $path = shift @ARGV) {
339            my $text = read_file($path) || die "can't read $path: $!";
340    
341            # strip html
342            $text =~ s!</?[^>]+>! !gs;
343    
344            $text =~ s!\s+! !gs;
345    
346            print "-- $text --";
347    
348            play_speak_hr( $text );
349            exit;
350    }
351    
352    my $prompt = "Pričaj: ";
353    
354    while ( defined ($_ = $term->readline($prompt)) ) {
355            $term->addhistory( $_ );
356            play_speak_hr( $_ );
357  }  }
358    
359    

Legend:
Removed from v.4  
changed lines
  Added in v.5

  ViewVC Help
Powered by ViewVC 1.1.26