Adds support for flite to speechd 0.56

Written by Paul Bredbury <brebs@sent.com>


--- speechd-orig	2010-08-18 22:44:44.000000000 +0700
+++ speechd	2010-08-19 00:37:48.000000000 +0700
@@ -8,8 +8,9 @@
 #
 # Requirements:
 #  * A speech synthesis package.  Support is currently provided for Festival,
-#    rsynth, and IBM ViaVoice TTS.
+#    flite, rsynth, and IBM ViaVoice TTS.
 #     - Festival:  http://www.cstr.ed.ac.uk/projects/festival/
+#     - flite:  http://cmuflite.org/
 #     - rsynth:  ftp://ftp.cdrom.com/pub/linux/sunsite/apps/sound/speech/
 #     - ViaVoice: http://www-3.ibm.com/software/speech/dev/ttssdk_linux.html
 #  * Perl (duh)
@@ -64,7 +65,7 @@
 #CMDLINE HELP BEGIN
 
 sub cmdlinehelp {
-  print "Usage: speechd [-qQf] [-H <host>] [-P <port>] [-s <festival|rsynth|viavoice>] [-V <ViaVoice voice>]\n";
+  print "Usage: speechd [-qQf] [-H <host>] [-P <port>] [-s <festival|flite|rsynth|viavoice>] [-V <ViaVoice voice>]\n";
   print "    or speechd [-h]\n";
   print "       -q  Quiet mode (Supresses STDOUT)\n";
   print "       -Q  Very quiet mode (Supresses STDOUT and STDERR)\n";
@@ -190,7 +191,11 @@
 
 print 'Speech synthesis system = "',$synth,'"',"\n";
 
-if ($synth eq 'rsynth') {
+if ($synth eq 'flite') {
+    @cmd = qw(flite -t);
+    print "cmd = @cmd\n";
+    &use_flite;
+} elsif ($synth eq 'rsynth') {
   if ($use_esd) {
     print "rsynth does not seem to work with esd.\n";
     @cmd = qw(esddsp say);
@@ -208,7 +213,7 @@
   }
   &use_rsynth;
 } elsif ($synth eq 'festival') {
-  # speical cases here... need to fork and exec...bummer
+  # special cases here... need to fork and exec...bummer
   if ($use_esd) 
   { 
     @cmd = qw(esddsp festival --server);
@@ -244,7 +249,7 @@
 ############################
 
 ##############################
-#DEFINITINO OF FUNCTIONS BEGIN
+#DEFINITION OF FUNCTIONS BEGIN
 
 sub use_festival_SayText {
   my $info;
@@ -303,6 +308,31 @@
   }
 }
 
+sub use_flite {
+  open( FIFO, "<$fifo" ) || die "can't read from $fifo $!\n";
+  while(1) {
+    # reads will block till someone writes something
+    my $text = <FIFO>; 
+
+    if (defined $text) {
+      # Strip single quotes so contractions are treated as single words by string conversion 
+      # & convert "_" characters to " ".
+      $text =~ tr/([_'])/ /d;
+      # convert to lowercase so string substitution isn't case sensitive
+      $text = lc ($text);
+      # This does the string conversion.
+      $text =~ s/(\w+)/$wordsub{$1} || $1/eg;
+
+      print "Output: $text";
+      system(@cmd,$text);
+      print "loop\n";
+      #close FIFO;
+    }
+    sleep 2;  # this is recommended by the perlipc
+              # manpage to avoid dup signals
+  }
+}
+
 sub use_rsynth {
   open( FIFO, "<$fifo" ) || die "can't read from $fifo $!\n";
   while(1) {
@@ -314,7 +344,7 @@
       #close FIFO;
     }
     sleep 2;  # this is recommended by the perlipc
-            # manpage to avoid dup signals
+              # manpage to avoid dup signals
   }
 }
 
@@ -472,8 +502,8 @@
 =item 
 C<-s pkg>  
 
-Sets the speech synthesis package to use.  pkg can be either 
-'festival' or 'rsynth'.
+Sets the speech synthesis package to use.  pkg can be 
+'festival', 'flite' or 'rsynth'.
 
 =item 
 C<-e>  
@@ -563,7 +593,9 @@
 
 The Festival voice synthesis package:  I<http://www.cstr.ed.ac.uk/projects/festival/>
 
-The rsynth voice sysnthesis package:  I<ftp://ftp.cdrom.com/pub/linux/sunsite/apps/sound/speech/>
+The flite voice synthesis package:  I<http://cmuflite.org/>
+
+The rsynth voice synthesis package:  I<ftp://ftp.cdrom.com/pub/linux/sunsite/apps/sound/speech/>
 
 The IBM ViaVoice TTS SDK package: I<http://www-3.ibm.com/software/speech/dev/ttssdk_linux.html>
 
