package Voice; # ::: External modules used by this module ::: # use IO::Socket; ################################################# # Method: Voice->new # Description: Object Constructor method ################################################# sub new { # bless a new object shift; my $self = {}; bless($self); # Set params passed for the object my ($server, $port) = ('localhost', 1314); # ::: Set Object Parameters ::: # $self->{ERROR} = undef; # error (duh!) $self->{SERVER} = $server; # festival server $self->{PORT} = $port; # festival port $self->{PRO} = 'tcp'; # connection protocol $self->{CONN} = undef; # connection object # return the object return $self; } # end-new # ----------------------------------------------- ################################################# # Method: Voice->open # Description: open the festival connection ################################################# sub open { # set as method my $self = shift; # create a connection to the festival server using IO::Socket::INET if ($self->{CONN} = IO::Socket::INET->new( Proto => $self->{PRO}, PeerAdr => $self->{SERVER}, PeerPort => $self->{PORT} )) { } # end-if else { # set the error string $self->{ERROR} = "Could not open connection to the festival server!"; } # end-else } # end-open # ----------------------------------------------- ################################################# # Method: Voice->speak # Description: say the sentence ################################################# sub speak { # set as method my $self = shift; # read in the sentence my ($sentence) = @_; my $buffer = "(SayText \"" . $sentence . "\")\n"; # say the sentence if ( syswrite($self->{CONN}, $buffer, length($buffer) ) ) { } # end-if else { # set the error string $self->{ERROR} = "Could not say sentence!"; } # end-else } # end-prepare # ----------------------------------------------- ################################################# # Method: Voice->close # Description: close the festival connection ################################################# sub close { # set as method my $self = shift; # close the IO::Socket::INET connection shutdown($self->{CONN}, 2); close($self->{CONN}); } # end-close # ----------------------------------------------- 1;