00001 /* $Id: festtalk.hh,v 1.17 2003/07/22 05:08:42 tetron Exp $ */ 00002 00003 #ifndef FESTTALK_HH 00004 #define FESTTALK_HH 00005 00006 /** @file festtalk.hh 00007 Defines FestTalk class, a subclass of LocalTalkative that speaks through festival voice synthesis library. 00008 @author Reed Hedges <reed@zerohour.net> November, 2001 00009 Portions of this code were developed at the University of Massachusetts 00010 00011 */ 00012 00013 00014 /* an idea for future improvement: be a listener to the voice property directly, and only set the voice (with festival_eval_command) when it changes. */ 00015 00016 00017 #include <stdio.h> 00018 #include <stdlib.h> 00019 #include <vos/corelibs/vos/vos.hh> 00020 #include "talkative.hh" 00021 00022 00023 /** A subclass of LocalTalkative that sends "SayText" commands to a festival server. 00024 Use FestTalk::registerExtenders() to register FestTalk as a local 00025 metaobject, and regular RemoteTalkative as a remote metaobject, with the factory. 00026 @author reed 12/01 00027 @bug Due to a possible bug in Festival the first "say" message fails. Manually send 00028 an initial message (with do_say) to get around this. 00029 */ 00030 00031 00032 class FestTalk : public LocalTalkative { 00033 00034 public: 00035 00036 /** An exception that indicates a general error communicating to server through network socket. (use ServerCommError::what() to get a descriptive string) */ 00037 class ServerCommError : public runtime_error { 00038 public: 00039 ServerCommError(const string& s) : runtime_error(s) {} 00040 }; 00041 00042 protected: 00043 00044 int socket_fd; 00045 FILE *socket_fp; 00046 00047 static char* festival_host; 00048 static int festival_port; 00049 00050 00051 void festival_server_command(const char *cmd) throw (ServerCommError); 00052 void festival_server_saytext(const string& text) throw (ServerCommError); 00053 void open_server(char *host, int port) throw (ServerCommError); 00054 void close_server(); 00055 00056 public: 00057 00058 /** If non-null, then text to speak is broken up into SayText commands by these delimeters. */ 00059 char *phrase_delim; 00060 00061 /** Constructor: opens socket to Festival server at 127.0.0.1:1314 */ 00062 FestTalk(MetaObject *super) throw (ServerCommError); 00063 00064 /** Destructor: closes connection to festival server */ 00065 ~FestTalk(); 00066 00067 00068 /** Say message actuator. */ 00069 void do_say(TalkMessage& m) throw(ServerCommError); 00070 00071 /** Register metaobject extenders. This method takes care of all talkative extenders (local and remote). RemoteTalkative is used for remote objects and FestTalk is used for all local objects. */ 00072 static void registerExtenders(); 00073 00074 /** Static generator, for factory. */ 00075 static MetaObject* new_FestTalk(MetaObject* superobject, const string& type); 00076 00077 /** Set default host and port for the Festival server. To use a different server other than 127.0.0.1:3113, call before creating new FestTalk objects. 00078 @param host string contianing numerical host address. Default is "127.0.0.1". 00079 @param port int containing host port. Default is 3113. 00080 */ 00081 static void set_server(char *host = "127.0.0.1", int port = 1314); 00082 00083 }; 00084 00085 00086 #endif