in reply to Broken Pipe error when talking to Festival server
#test scriptpackage Voice; use strict; use warnings; require 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} = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "localhost", PeerPort => 1314) || die($!); # return the object return $self; } # end-new # ----------------------------------------------- ################################################# # 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"; my $buffer = "(SayText \"" . $sentence . "\")"; #print "$buffer\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;
#!/usr/bin/perl use warnings; use strict; use lib '.'; use Voice; my $voice = Voice->new; $voice->speak( 'foobar foobar foobar' ); $voice->close;
|
|---|