I found out quickly that just piping
date
into Festival won't make you happy. I wrote this to force a pronunciation. It's simple Perl, and it doesn't deal with Festival directly. But it gives me the pronunciation I want.If it's useful to you, use in good health.
#!/usr/bin/perl # */15 8-17 * * 1-5 ~/bin/curr_time.pl | /usr/bin/festival --tts &> /dev/null use 5.010 ; use strict ; use warnings ; use Data::Dumper ; use subs qw( hour minute ampm ) ; my @time = localtime ; my @output ; my @hour = qw{ Twelve One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve } ; push @output , hour(@time) ; push @output , minute(@time) ; push @output , ampm(@time) ; say join ' ' , @output ; # -- hour ------------------- sub hour { my @time = @_ ; my $hour ; if ( $time[2] % 12 == 0 ) { $hour = 12 ; } elsif ( $time[2] > 12 ) { $hour = $time[2] - 12 ; } else { $hour = $time[2] ; } return $hour[ $hour ]; } # -- minute ----------------- sub minute { my @time = @_ ; my $minute = sprintf '%d' , $time[1] ; if ( $time[1] < 10 ) { $minute = 'oh ' . $minute ; } if ( $time[1] == 0 ) { $minute = '' ; } return $minute; } # -- a.m. - p.m. ------------ sub ampm { my @time = @_ ; my $m ; if ( $time[2] == 0 && $time[1] == 0 ) { $m = 'Midnight' ; } elsif ( $time[2] == 12 && $time[1] == 0 ) { $m = 'Noon' ; } elsif ( $time[2] < 12 ) { $m = 'A M' ; } else { $m = 'P M' ; } return $m; }
Sounds like a similar idea to DateTime::Format::Human (http://search.cpan.org/~jhoblitt/DateTime-Format-Human-0.01/)
ReplyDeleteI'll have to look into that.
ReplyDeleteSteve,
ReplyDeletehaving tested it, no. I want it to say "Two 27 P M" and not "a little after twenty-five past two in the afternoon". I just want to be sure it says "A.M." and not "am".