#!/usr/bin/perl
use strict;
use locale;
use POSIX qw (locale_h);
setlocale(LC_CTYPE, 'ru_RU.utf8');
setlocale(LC_ALL, 'ru_RU.utf8');
use strict;
use warnings;
use utf8;
use Encode qw/decode/;
binmode STDOUT, ':utf8';
my ($text, $word);
if ( defined $ARGV[0] && length $ARGV[0]) {
$text = $ARGV[0];
} else {
print "\n\nsay.pl [text to speech]\n\n";
exit;
}
utf8::decode($text);
$text =~ s/#/ /g;
$text =~ s/\r{1,}/#/g;
$text =~ s/\n{1,}/#/g;
$text =~ s/…/\./g;
$text =~ s/\.{1,}/\./g;
$text =~ s/(а-яА-ЯA-Za-z0-9){2,}\./$1#/g;
#$text =~ s/(а-яА-ЯA-Za-z0-9\-\s\,\;\
/ /g;
$text =~ s/\./#/g;
#$text =~ s/\W/ /g;
$text =~ s/[^\w\_\.\#]/ /g;
my @data = split /#/, $text;
foreach $text ( @data ) {
$text =~ s/\s{1,}/ /g;
$text = lc($text);
utf8::decode($text);
if ( length $text ) {
my @aa = split /\s/, $text;
my @bb = ();
foreach $word ( @aa ) {
push @bb, $word;
}
$text = join ' ', @bb;
say_text($text);
}
}
quit();
sub say_text {
my ($text) = @_;
my $cmd;
$cmd=qq~festival -b '(begin (voice_msu_ru_nsh_clunits) (SayText "$text" nil) )'~;
system($cmd);
}
sub quit {
system(qq~festival -b '((quit))'~);
exit;
}