Hi, well I played abit with it, and got something that works. :-) Now I'm not an expert on OO programming, so just take this as is. From what I can observe, there is somekind of problem when you you set $self->{CONN} = undef in new(), and then try to redefine it in open. So I removed the open() method, and it works from the commandline. In your cgi, there may be additional complications because of the server. Anyways, here is a working module and test script.
package 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;
#test script
#!/usr/bin/perl use warnings; use strict; use lib '.'; use Voice; my $voice = Voice->new; $voice->speak( 'foobar foobar foobar' ); $voice->close;

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Broken Pipe error when talking to Festival server by zentara
in thread Broken Pipe error when talking to Festival server by rsiedl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.