| | 102 | emit_word(Econtext *self, guint offset, guint len, guint id) |
| | 103 | { |
| | 104 | post_message(self, gst_structure_new("espeak-word", |
| | 105 | "offset", G_TYPE_UINT, offset, |
| | 106 | "len", G_TYPE_UINT, len, |
| | 107 | "id", G_TYPE_UINT, id, |
| | 108 | NULL)); |
| | 109 | } |
| | 110 | |
| | 111 | static void |
| | 112 | emit_sentence(Econtext *self, guint offset, guint len, guint id) |
| | 113 | { |
| | 114 | post_message(self, gst_structure_new("espeak-sentence", |
| | 115 | "offset", G_TYPE_UINT, offset, |
| | 116 | "len", G_TYPE_UINT, len, |
| | 117 | "id", G_TYPE_UINT, id, |
| | 118 | NULL)); |
| | 119 | } |
| | 120 | |
| | 121 | static void |
| 109 | | GstStructure *data = gst_structure_new("espeak-mark", |
| 110 | | "offset", G_TYPE_UINT, offset, |
| 111 | | "mark", G_TYPE_STRING, mark, |
| 112 | | NULL); |
| 113 | | if (!self->bus) |
| 114 | | self->bus = gst_element_get_bus(self->emitter); |
| 115 | | GstMessage *msg = gst_message_new_element(GST_OBJECT(self->emitter), data); |
| 116 | | gst_bus_post(self->bus, msg); |
| | 124 | post_message(self, gst_structure_new("espeak-mark", |
| | 125 | "offset", G_TYPE_UINT, offset, |
| | 126 | "mark", G_TYPE_STRING, mark, |
| | 127 | NULL)); |
| 238 | | inline gsize word(Econtext *self, Espin *spin, gsize size_to_play) |
| 239 | | { |
| 240 | | gsize spin_size = spin->sound->len; |
| 241 | | gsize event; |
| 242 | | gsize sample_offset = 0; |
| 243 | | |
| 244 | | for (event = spin->events_pos; TRUE; ++event) |
| 245 | | { |
| 246 | | espeak_EVENT *i = &g_array_index(spin->events, espeak_EVENT, event); |
| 247 | | |
| 248 | | GST_DEBUG("event=%zd i->type=%d i->text_position=%d", |
| 249 | | event, i->type, i->text_position); |
| 250 | | |
| 251 | | if (i->type == espeakEVENT_LIST_TERMINATED) |
| 252 | | { |
| 253 | | sample_offset = spin_size; |
| 254 | | break; |
| 255 | | } |
| 256 | | else if (i->type == espeakEVENT_WORD) |
| 257 | | { |
| 258 | | if (i->text_position != spin->last_word) |
| 259 | | { |
| 260 | | emit_word(self, i->text_position, i->length); |
| 261 | | spin->last_word = i->text_position; |
| 262 | | } |
| 263 | | sample_offset = i[1].sample*2; |
| 264 | | break; |
| 265 | | } |
| 266 | | } |
| 267 | | |
| 268 | | return sample_offset - spin->sound_offset; |
| 269 | | } |
| 283 | | guint mark_offset = 0; |
| 284 | | const gchar *mark_name = NULL; |
| 285 | | |
| 286 | | for (event = spin->events_pos; TRUE; ++event) |
| 287 | | { |
| 288 | | espeak_EVENT *i = &g_array_index(spin->events, espeak_EVENT, event); |
| 289 | | |
| 290 | | GST_DEBUG("event=%zd i->type=%d i->text_position=%d", |
| 291 | | event, i->type, i->text_position); |
| 292 | | |
| 293 | | if (i->type == espeakEVENT_LIST_TERMINATED) |
| 294 | | { |
| 295 | | sample_offset = spin_size; |
| 296 | | break; |
| 297 | | } |
| 298 | | else if (i->type == espeakEVENT_MARK) |
| 299 | | { |
| 300 | | if (i->sample == 0) |
| 301 | | { |
| 302 | | if (spin->sound_offset == 0) |
| 303 | | emit_mark(self, i->text_position, i->id.name); |
| 304 | | continue; |
| 305 | | } |
| 306 | | |
| 307 | | mark_offset = i->text_position; |
| 308 | | mark_name = i->id.name; |
| 309 | | sample_offset = i->sample*2; |
| 310 | | break; |
| 311 | | } |
| 312 | | } |
| 313 | | |
| 314 | | spin->mark_offset = mark_offset; |
| 315 | | spin->mark_name = mark_name; |
| | 255 | espeak_EVENT *i = &g_array_index(spin->events, espeak_EVENT, spin->events_pos); |
| | 256 | |
| | 257 | GST_DEBUG("event=%zd i->type=%d i->text_position=%d", |
| | 258 | event, i->type, i->text_position); |
| | 259 | |
| | 260 | |
| | 261 | if (i->type == espeakEVENT_LIST_TERMINATED) { |
| | 262 | sample_offset = spin_size; |
| | 263 | } else { |
| | 264 | switch (i->type) { |
| | 265 | case espeakEVENT_MARK: |
| | 266 | emit_mark(self, i->text_position, i->id.name); |
| | 267 | break; |
| | 268 | case espeakEVENT_WORD: |
| | 269 | emit_word(self, i->text_position, i->length, i->id.number); |
| | 270 | break; |
| | 271 | case espeakEVENT_SENTENCE: |
| | 272 | emit_sentence(self, i->text_position, i->length, i->id.number); |
| | 273 | break; |
| | 274 | } |
| | 275 | } |
| | 276 | |
| | 277 | if (!sample_offset) { |
| | 278 | sample_offset = i->sample*2; |
| | 279 | } |
| 323 | | { |
| 324 | | case ESPEAK_TRACK_WORD: |
| 325 | | size_to_play = word(self, spin, size_to_play); |
| 326 | | break; |
| 327 | | case ESPEAK_TRACK_MARK: |
| 328 | | size_to_play = mark(self, spin, size_to_play); |
| 329 | | break; |
| 330 | | default: |
| 331 | | size_to_play = whole(spin, size_to_play); |
| | 287 | { |
| | 288 | case ESPEAK_TRACK_WORD: |
| | 289 | case ESPEAK_TRACK_MARK: |
| | 290 | size_to_play = events(self, spin, size_to_play); |
| | 291 | break; |
| | 292 | default: |
| | 293 | size_to_play = whole(spin, size_to_play); |
| | 294 | break; |