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 data_ts = (interface_data_ts_t *)data_ptr;
00053 memset(data_ptr, 0, data_size);
00054 add_fieldinfo(IFT_STRING, "text", 1024, data->text);
00055 add_fieldinfo(IFT_UINT32, "msgid", 1, &data->msgid);
00056 add_fieldinfo(IFT_BOOL, "final", 1, &data->final);
00057 add_fieldinfo(IFT_FLOAT, "duration", 1, &data->duration);
00058 add_messageinfo("SayMessage");
00059 unsigned char tmp_hash[] = {0x28, 0x11, 0x46, 0x87, 0xb1, 0x65, 0x92, 0x96, 0xe6, 0x6e, 0x18, 0x8a, 0xdc, 0x8, 0xb0, 0x69};
00060 set_hash(tmp_hash);
00061 }
00062
00063
00064 SpeechSynthInterface::~SpeechSynthInterface()
00065 {
00066 free(data_ptr);
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 char *
00076 SpeechSynthInterface::text() const
00077 {
00078 return data->text;
00079 }
00080
00081
00082
00083
00084
00085 size_t
00086 SpeechSynthInterface::maxlenof_text() const
00087 {
00088 return 1024;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 void
00098 SpeechSynthInterface::set_text(const char * new_text)
00099 {
00100 strncpy(data->text, new_text, sizeof(data->text));
00101 data_changed = true;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111 uint32_t
00112 SpeechSynthInterface::msgid() const
00113 {
00114 return data->msgid;
00115 }
00116
00117
00118
00119
00120
00121 size_t
00122 SpeechSynthInterface::maxlenof_msgid() const
00123 {
00124 return 1;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134 void
00135 SpeechSynthInterface::set_msgid(const uint32_t new_msgid)
00136 {
00137 data->msgid = new_msgid;
00138 data_changed = true;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147 bool
00148 SpeechSynthInterface::is_final() const
00149 {
00150 return data->final;
00151 }
00152
00153
00154
00155
00156
00157 size_t
00158 SpeechSynthInterface::maxlenof_final() const
00159 {
00160 return 1;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 void
00170 SpeechSynthInterface::set_final(const bool new_final)
00171 {
00172 data->final = new_final;
00173 data_changed = true;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 float
00185 SpeechSynthInterface::duration() const
00186 {
00187 return data->duration;
00188 }
00189
00190
00191
00192
00193
00194 size_t
00195 SpeechSynthInterface::maxlenof_duration() const
00196 {
00197 return 1;
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 void
00209 SpeechSynthInterface::set_duration(const float new_duration)
00210 {
00211 data->duration = new_duration;
00212 data_changed = true;
00213 }
00214
00215
00216 Message *
00217 SpeechSynthInterface::create_message(const char *type) const
00218 {
00219 if ( strncmp("SayMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00220 return new SayMessage();
00221 } else {
00222 throw UnknownTypeException("The given type '%s' does not match any known "
00223 "message type for this interface type.", type);
00224 }
00225 }
00226
00227
00228
00229
00230
00231 void
00232 SpeechSynthInterface::copy_values(const Interface *other)
00233 {
00234 const SpeechSynthInterface *oi = dynamic_cast<const SpeechSynthInterface *>(other);
00235 if (oi == NULL) {
00236 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00237 type(), other->type());
00238 }
00239 memcpy(data, oi->data, sizeof(SpeechSynthInterface_data_t));
00240 }
00241
00242 const char *
00243 SpeechSynthInterface::enum_tostring(const char *enumtype, int val) const
00244 {
00245 throw UnknownTypeException("Unknown enum type %s", enumtype);
00246 }
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 SpeechSynthInterface::SayMessage::SayMessage(const char * ini_text) : Message("SayMessage")
00260 {
00261 data_size = sizeof(SayMessage_data_t);
00262 data_ptr = malloc(data_size);
00263 memset(data_ptr, 0, data_size);
00264 data = (SayMessage_data_t *)data_ptr;
00265 data_ts = (message_data_ts_t *)data_ptr;
00266 strncpy(data->text, ini_text, 1024);
00267 add_fieldinfo(IFT_STRING, "text", 1024, data->text);
00268 }
00269
00270 SpeechSynthInterface::SayMessage::SayMessage() : Message("SayMessage")
00271 {
00272 data_size = sizeof(SayMessage_data_t);
00273 data_ptr = malloc(data_size);
00274 memset(data_ptr, 0, data_size);
00275 data = (SayMessage_data_t *)data_ptr;
00276 data_ts = (message_data_ts_t *)data_ptr;
00277 add_fieldinfo(IFT_STRING, "text", 1024, data->text);
00278 }
00279
00280
00281 SpeechSynthInterface::SayMessage::~SayMessage()
00282 {
00283 free(data_ptr);
00284 }
00285
00286
00287
00288
00289 SpeechSynthInterface::SayMessage::SayMessage(const SayMessage *m) : Message("SayMessage")
00290 {
00291 data_size = m->data_size;
00292 data_ptr = malloc(data_size);
00293 memcpy(data_ptr, m->data_ptr, data_size);
00294 data = (SayMessage_data_t *)data_ptr;
00295 data_ts = (message_data_ts_t *)data_ptr;
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305 char *
00306 SpeechSynthInterface::SayMessage::text() const
00307 {
00308 return data->text;
00309 }
00310
00311
00312
00313
00314
00315 size_t
00316 SpeechSynthInterface::SayMessage::maxlenof_text() const
00317 {
00318 return 1024;
00319 }
00320
00321
00322
00323
00324
00325
00326
00327 void
00328 SpeechSynthInterface::SayMessage::set_text(const char * new_text)
00329 {
00330 strncpy(data->text, new_text, sizeof(data->text));
00331 }
00332
00333
00334
00335
00336
00337
00338 Message *
00339 SpeechSynthInterface::SayMessage::clone() const
00340 {
00341 return new SpeechSynthInterface::SayMessage(this);
00342 }
00343
00344
00345
00346
00347 bool
00348 SpeechSynthInterface::message_valid(const Message *message) const
00349 {
00350 const SayMessage *m0 = dynamic_cast<const SayMessage *>(message);
00351 if ( m0 != NULL ) {
00352 return true;
00353 }
00354 return false;
00355 }
00356
00357
00358 EXPORT_INTERFACE(SpeechSynthInterface)
00359
00360
00361
00362 }