#!/usr/bin/perl # # Speakit # Speaks argument # 0.2 Added staleness checking # 0.1 First working version my $expire = 3; # 3 seconds my $timestamp = time; # Send the data to zaza2 #sub speakit { # my $speechtext = <@ARGV>; use strict; use Socket; my ($remote, $port, $iaddr, $paddr, $proto, $line, $text, $i); $remote = 'zazaconsole.exhibits.thetech.org'; $port = 80; # speech port if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; if ((time - $timestamp) <= $expire) { ## Works on new Perl only # print "Speech data: "; # $i = 0; # while (<@ARGV>) { # $text = $_; # if ($i > 0) { # print " $text"; # print SOCK " $text"; # } else { # print "$text"; # print SOCK "$text"; # } # $i++; # } # print "\r\n"; # print SOCK "\r\n"; my $stringified; for $i (0 .. $#ARGV) { # print $ARGV[$i] . "\n"; if ($i == 0 ) { $stringified = $ARGV[$i]; } else { $stringified = $stringified . "+" . $ARGV[$i]; } } print "Sent data: $stringified\n"; print SOCK "GET /cgi-bin/voiceClient?speechtext=" . $stringified . " HTTP/1.0\n"; # sleep 1; close (SOCK) || die "close: $!"; } else { # sleep 1; close (SOCK) || die "Speech data too stale, close: $!"; } #}