00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <interfaces/SpeechSynthInterface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 SpeechSynthInterface::SpeechSynthInterface() : Interface()
00048 {
00049 data_size = sizeof(SpeechSynthInterface_data_t);
00050 data_ptr = malloc(data_size);
00051 data = (SpeechSynthInterface_data_t *)data_ptr;
00052 memset(data_ptr, 0, data_size);
00053 add_fieldinfo(IFT_STRING, "text", 1024, data->text);
00054 add_fieldinfo(IFT_UINT, "msgid", 1, &data->msgid);
00055 add_fieldinfo(IFT_BOOL, "final", 1, &data->final);
00056 add_fieldinfo(IFT_FLOAT, "duration", 1, &data->duration);
00057 add_messageinfo("SayMessage");
00058 unsigned char tmp_hash[] = {0xd4, 0x89, 0x24, 0x17, 0x5a, 0xb8, 0xa9, 0x8e, 0x63, 0x80, 0xb3, 0xed, 0xb7, 0xc3, 0xb5, 0x90};
00059 set_hash(tmp_hash);
00060 }
00061
00062
00063 SpeechSynthInterface::~SpeechSynthInterface()
00064 {
00065 free(data_ptr);
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 char *
00075 SpeechSynthInterface::text() const
00076 {
00077 return data->text;
00078 }
00079
00080
00081
00082
00083
00084 size_t
00085 SpeechSynthInterface::maxlenof_text() const
00086 {
00087 return 1024;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 void
00097 SpeechSynthInterface::set_text(const char * new_text)
00098 {
00099 strncpy(data->text, new_text, sizeof(data->text));
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109 unsigned int
00110 SpeechSynthInterface::msgid() const
00111 {
00112 return data->msgid;
00113 }
00114
00115
00116
00117
00118
00119 size_t
00120 SpeechSynthInterface::maxlenof_msgid() const
00121 {
00122 return 1;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 void
00133 SpeechSynthInterface::set_msgid(const unsigned int new_msgid)
00134 {
00135 data->msgid = new_msgid;
00136 }
00137
00138
00139
00140
00141
00142
00143
00144 bool
00145 SpeechSynthInterface::is_final() const
00146 {
00147 return data->final;
00148 }
00149
00150
00151
00152
00153
00154 size_t
00155 SpeechSynthInterface::maxlenof_final() const
00156 {
00157 return 1;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166 void
00167 SpeechSynthInterface::set_final(const bool new_final)
00168 {
00169 data->final = new_final;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 float
00181 SpeechSynthInterface::duration() const
00182 {
00183 return data->duration;
00184 }
00185
00186
00187
00188
00189
00190 size_t
00191 SpeechSynthInterface::maxlenof_duration() const
00192 {
00193 return 1;
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 void
00205 SpeechSynthInterface::set_duration(const float new_duration)
00206 {
00207 data->duration = new_duration;
00208 }
00209
00210
00211 Message *
00212 SpeechSynthInterface::create_message(const char *type) const
00213 {
00214 if ( strncmp("SayMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00215 return new SayMessage();
00216 } else {
00217 throw UnknownTypeException("The given type '%s' does not match any known "
00218 "message type for this interface type.", type);
00219 }
00220 }
00221
00222
00223
00224
00225
00226 void
00227 SpeechSynthInterface::copy_values(const Interface *other)
00228 {
00229 const SpeechSynthInterface *oi = dynamic_cast<const SpeechSynthInterface *>(other);
00230 if (oi == NULL) {
00231 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00232 type(), other->type());
00233 }
00234 memcpy(data, oi->data, sizeof(SpeechSynthInterface_data_t));
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 SpeechSynthInterface::SayMessage::SayMessage(const char * ini_text) : Message("SayMessage")
00249 {
00250 data_size = sizeof(SayMessage_data_t);
00251 data_ptr = malloc(data_size);
00252 memset(data_ptr, 0, data_size);
00253 data = (SayMessage_data_t *)data_ptr;
00254 strncpy(data->text, ini_text, 1024);
00255 add_fieldinfo(IFT_STRING, "text", 1024, data->text);
00256 }
00257
00258 SpeechSynthInterface::SayMessage::SayMessage() : Message("SayMessage")
00259 {
00260 data_size = sizeof(SayMessage_data_t);
00261 data_ptr = malloc(data_size);
00262 memset(data_ptr, 0, data_size);
00263 data = (SayMessage_data_t *)data_ptr;
00264 add_fieldinfo(IFT_STRING, "text", 1024, data->text);
00265 }
00266
00267
00268 SpeechSynthInterface::SayMessage::~SayMessage()
00269 {
00270 free(data_ptr);
00271 }
00272
00273
00274
00275
00276 SpeechSynthInterface::SayMessage::SayMessage(const SayMessage *m) : Message("SayMessage")
00277 {
00278 data_size = m->data_size;
00279 data_ptr = malloc(data_size);
00280 memcpy(data_ptr, m->data_ptr, data_size);
00281 data = (SayMessage_data_t *)data_ptr;
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291 char *
00292 SpeechSynthInterface::SayMessage::text() const
00293 {
00294 return data->text;
00295 }
00296
00297
00298
00299
00300
00301 size_t
00302 SpeechSynthInterface::SayMessage::maxlenof_text() const
00303 {
00304 return 1024;
00305 }
00306
00307
00308
00309
00310
00311
00312
00313 void
00314 SpeechSynthInterface::SayMessage::set_text(const char * new_text)
00315 {
00316 strncpy(data->text, new_text, sizeof(data->text));
00317 }
00318
00319
00320
00321
00322
00323
00324 Message *
00325 SpeechSynthInterface::SayMessage::clone() const
00326 {
00327 return new SpeechSynthInterface::SayMessage(this);
00328 }
00329
00330
00331
00332 bool
00333 SpeechSynthInterface::message_valid(const Message *message) const
00334 {
00335 const SayMessage *m0 = dynamic_cast<const SayMessage *>(message);
00336 if ( m0 != NULL ) {
00337 return true;
00338 }
00339 return false;
00340 }
00341
00342
00343 EXPORT_INTERFACE(SpeechSynthInterface)
00344
00345
00346
00347 }