Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // preprocessor directives
- #include <festival.h>
- #include <sys/time.h>
- using namespace std;
- //
- EST_Val default_val_float(0.0f);
- // functions for accessing word start & end times in an utterance tree
- // returns segment start time
- EST_Val ff_seg_start(EST_Item* s)
- {
- EST_Item* n = as(s, "Segment");
- if (prev(n) == 0) return default_val_float;
- return prev(n)->F("end", 0);
- } // ff_seg_start(EST_Item*)
- // returns segment end time
- EST_Val ff_seg_end(EST_Item* s)
- {
- return s->F("end", 0);
- } // ff_seg_end(EST_Item*)
- // returns syllable end time
- EST_Val ff_syl_end(EST_Item* s)
- {
- EST_Item* n = as(s, "SylStructure");
- if (daughtern(n) == 0) return default_val_float;
- return ff_seg_end(daughtern(n));
- } // ff_syl_end(EST_Item*)
- // returns word start time
- EST_Val ff_word_start(EST_Item* s)
- {
- EST_Item* n = as(s, "SylStructure");
- if (daughter1(daughter1(n)) == 0) return default_val_float;
- return ff_seg_start(daughter1(daughter1(n)));
- } // ff_word_start(EST_Item*)
- // returns word end time
- EST_Val ff_word_end(EST_Item* s)
- {
- EST_Item* n = as(s, "SylStructure");
- if (daughtern(n) == 0) return default_val_float;
- return ff_syl_end(daughtern(n));
- } // ff_word_end(EST_Item*)
- // executes main program code
- int main(int argc, char** argv)
- {
- if (argc < 2)
- {
- printf(">> ERROR: Invalid arguments...\n\n");
- return 1;
- }
- // Festival local variables
- int heap_size = 210000; // default scheme heap size
- int load_init_files = 1; // we want the festival init files loaded
- // initialize the Festival text-to-speech (TTS) engine
- festival_initialize(load_init_files, heap_size);
- // iterate through text input; append words to string str
- EST_String str;
- for(int i = 1; i < argc; ++i)
- {
- //printf("arg %d: %s\n", i, argv[i]);
- str += argv[i];
- str += " ";
- }
- // Lisp command to create and synthesize a text utterance with the user input
- EST_String command1 = "(set! utt1 (utt.synth(Utterance Text \"" +
- str + "\")))";
- // Lisp command to save the utterance to a file
- EST_String command2 = "(utt.save utt1 \"inputText.utt\")";
- // evaluate the Lisp command
- bool success1 = festival_eval_command(command1);
- bool success2 = festival_eval_command(command2);
- //cout << "Command[1] success: " << success1 << endl;
- //cout << "Command[2] success: " << success2 << endl;
- // load the utterance previously made
- EST_Utterance myUtt;
- myUtt.load("inputText.utt");
- // print out how many words are in this utterance
- EST_Relation myRel = *myUtt.relation("Word");
- cout << "# words: " << myRel.length() << endl;
- // iterate through the utterance tree to get each word
- EST_Item* s = NULL;
- for (s = myUtt.relation("Word")->head(); s != 0; s = next(s))
- {
- //print out features of the word: name, start time, end time
- cout << "Word: " << s->S("name");
- cout << "\tstart: "<< ff_word_start(s);
- cout << "\tend: " << ff_word_end(s) << endl;
- // print out the "word_end" feature of the word <-- does not work
- //cout << s->A("word_end") << endl;
- }
- // synthesize the parameterized text and time its duration
- timeval t_start, t_stop;
- gettimeofday(&t_start, NULL);
- festival_say_text(str);
- gettimeofday(&t_stop, NULL);
- double t_elapsed = (t_stop.tv_sec + (double)t_stop.tv_usec * 1e-6) -
- (t_start.tv_sec + (double)t_start.tv_usec * 1e-6);
- printf("Time elapsed: %.6f\n", t_elapsed);
- return 0;
- } // main(int, char**)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement