void item_unref_contents(cst_item *item) { /* unreference this item from contents, and delete contents */ /* if no one else is referencing it */ if (item && item->contents) { feat_remove(item->contents->relations,item->relation->name); if (feat_length(item->contents->relations) == 0) { delete_features(item->contents->relations); delete_features(item->contents->features); cst_utt_free(item->relation->utterance,item->contents); } item->contents = NULL; } }
cst_val *cst_args(char **argv, int argc, const char *description, cst_features *args) { /* parses the given arguments wrt the description */ cst_features *op_types = new_features(); cst_val *files = NULL; int i; const char *type; parse_description(description,op_types); for (i=1; i<argc; i++) { if (argv[i][0] == '-') { if ((!feat_present(op_types,argv[i])) || (cst_streq("-h",argv[i])) || (cst_streq("-?",argv[i])) || (cst_streq("--help",argv[i])) || (cst_streq("-help",argv[i]))) parse_usage(argv[0],"","",description); else { type = feat_string(op_types,argv[i]); if (cst_streq("<binary>",type)) feat_set_string(args,argv[i],"true"); else { if (i+1 == argc) parse_usage(argv[0], "missing argument for ",argv[i], description); if (cst_streq("<int>",type)) feat_set_int(args,argv[i],atoi(argv[i+1])); else if (cst_streq("<float>",type)) feat_set_float(args,argv[i],atof(argv[i+1])); else if (cst_streq("<string>",type)) feat_set_string(args,argv[i],argv[i+1]); else parse_usage(argv[0], "unknown arg type ",type, description); i++; } } } else files = cons_val(string_val(argv[i]),files); } delete_features(op_types); return val_reverse(files); }
static cst_features *ssml_get_attributes(cst_tokenstream *ts) { cst_features *a = new_features(); const char* name, *val; set_charclasses(ts, ts->p_whitespacesymbols, ssml_singlecharsymbols_inattr, ts->p_prepunctuationsymbols, ts->p_postpunctuationsymbols); name = ts_get(ts); while (!cst_streq(">",name)) { if (cst_streq(name,"/")) feat_set_string(a,"_type","startend"); else { feat_set_string(a,"_type","start"); feat_set_string(a,"_name0",name); if (cst_streq("=",ts_get(ts))) { val = ts_get_quoted_remainder(ts); feat_set_string(a,"_val0",val); } } if (ts_eof(ts)) { fprintf(stderr,"ssml: unexpected EOF\n"); delete_features(a); return 0; } name = ts_get(ts); } set_charclasses(ts, ts->p_whitespacesymbols, ssml_singlecharsymbols_general, ts->p_prepunctuationsymbols, ts->p_postpunctuationsymbols); return a; }
string getPhonemes( const char* sText ) { string sRet; cst_features* args = new_features(); cst_voice* v; cst_utterance* u; cst_item* s; const char* name; //const cst_val* d; flite_init(); v = register_cmu_us_no_wave( NULL ); u = flite_synth_text( sText, v ); for ( s = relation_head( utt_relation( u, "Segment" ) ); s; s = item_next( s ) ) { sRet += item_feat_string( s, "name" ); float test = item_feat_float( s, "end" ); //d = segment_duration( s ); /* If its a vowel and is stressed output stress value */ if ( ( cst_streq( "+", ffeature_string( s, "ph_vc" ) ) ) && ( cst_streq( "1", ffeature_string( s, "R:SylStructure.parent.stress" ) ) ) ) { sRet += "1"; } sRet += " "; } delete_utterance( u ); delete_features( args ); return sRet; }
const cst_val *cart_interpret(cst_item *item, const cst_cart *tree) { /* Tree interpretation */ const cst_val *v=0; const cst_val *tree_val; const char *tree_feat = ""; cst_features *fcache; int r=0; int node=0; fcache = new_features_local(item_utt(item)->ctx); while (cst_cart_node_op(node,tree) != CST_CART_OP_LEAF) { #if CART_DEBUG cart_print_node(node,tree); #endif tree_feat = cst_cart_node_feat(node,tree); v = get_param_val(fcache,tree_feat,0); if (v == 0) { v = ffeature(item,tree_feat); feat_set(fcache,tree_feat,v); } #if CART_DEBUG val_print(stdout,v); printf("\n"); #endif tree_val = cst_cart_node_val(node,tree); if (cst_cart_node_op(node,tree) == CST_CART_OP_IS) r = val_equal(v,tree_val); else if (cst_cart_node_op(node,tree) == CST_CART_OP_LESS) r = val_less(v,tree_val); else if (cst_cart_node_op(node,tree) == CST_CART_OP_GREATER) r = val_greater(v,tree_val); else if (cst_cart_node_op(node,tree) == CST_CART_OP_IN) r = val_member(v,tree_val); else if (cst_cart_node_op(node,tree) == CST_CART_OP_MATCHES) r = cst_regex_match(cst_regex_table[val_int(tree_val)], val_string(v)); else { cst_errmsg("cart_interpret_question: unknown op type %d\n", cst_cart_node_op(node,tree)); cst_error(); } if (r) { /* Oh yes it is */ #if CART_DEBUG printf(" YES\n"); #endif node = cst_cart_node_yes(node,tree); } else { /* Oh no it isn't */ #if CART_DEBUG printf(" NO\n"); #endif node = cst_cart_node_no(node,tree); } } delete_features(fcache); return cst_cart_node_val(node,tree); }
int main(int argc, char **argv) { struct timeval tv; cst_voice *v; const char *filename; const char *outtype; int i; float durs; double time_start, time_end; int flite_verbose, flite_loop, flite_bench; int explicit_filename, explicit_text, explicit_phones; #define ITER_MAX 3 int bench_iter = 0; cst_features *extra_feats; filename = 0; outtype = "play"; /* default is to play */ flite_verbose = FALSE; flite_loop = FALSE; flite_bench = FALSE; explicit_text = explicit_filename = explicit_phones = FALSE; extra_feats = new_features(); flite_init(); for (i=1; i<argc; i++) { if (cst_streq(argv[i],"--version")) { flite_version(); return 1; } else if (cst_streq(argv[i],"-h") || cst_streq(argv[i],"--help") || cst_streq(argv[i],"-?")) flite_usage(); else if (cst_streq(argv[i],"-v")) flite_verbose = TRUE; else if (cst_streq(argv[i],"-l")) flite_loop = TRUE; else if (cst_streq(argv[i],"-b")) { flite_bench = TRUE; break; /* ignore other arguments */ } else if ((cst_streq(argv[i],"-o")) && (i+1 < argc)) { outtype = argv[i+1]; i++; } else if (cst_streq(argv[i],"-f") && (i+1 < argc)) { filename = argv[i+1]; explicit_filename = TRUE; i++; } else if (cst_streq(argv[i],"-pw")) { feat_set_string(extra_feats,"print_info_relation","Word"); feat_set(extra_feats,"post_synth_hook_func", uttfunc_val(&print_info)); } else if (cst_streq(argv[i],"-ps")) { feat_set_string(extra_feats,"print_info_relation","Segment"); feat_set(extra_feats,"post_synth_hook_func", uttfunc_val(&print_info)); } else if (cst_streq(argv[i],"-pr") && (i+1 < argc)) { feat_set_string(extra_feats,"print_info_relation",argv[i+1]); feat_set(extra_feats,"post_synth_hook_func", uttfunc_val(&print_info)); i++; } else if ((cst_streq(argv[i],"-set") || cst_streq(argv[i],"-s")) && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],0); i++; } else if (cst_streq(argv[i],"--seti") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"int"); i++; } else if (cst_streq(argv[i],"--setf") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"float"); i++; } else if (cst_streq(argv[i],"--sets") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"string"); i++; } else if (cst_streq(argv[i],"-p") && (i+1 < argc)) { filename = argv[i+1]; explicit_phones = TRUE; i++; } else if (cst_streq(argv[i],"-t") && (i+1 < argc)) { filename = argv[i+1]; explicit_text = TRUE; i++; } else if (filename) outtype = argv[i]; else filename = argv[i]; } if (filename == NULL) filename = "-"; /* stdin */ v = REGISTER_VOX(NULL); feat_copy_into(extra_feats,v->features); durs = 0.0; if (flite_bench) { outtype = "none"; filename = "A whole joy was reaping, but they've gone south, you should fetch azure mike."; explicit_text = TRUE; } loop: gettimeofday(&tv,NULL); time_start = (double)(tv.tv_sec)+(((double)tv.tv_usec)/1000000.0); if (explicit_phones) durs = flite_phones_to_speech(filename,v,outtype); else if ((strchr(filename,' ') && !explicit_filename) || explicit_text) durs = flite_text_to_speech(filename,v,outtype); else durs = flite_file_to_speech(filename,v,outtype); gettimeofday(&tv,NULL); time_end = ((double)(tv.tv_sec))+((double)tv.tv_usec/1000000.0); if (flite_verbose || (flite_bench && bench_iter == ITER_MAX)) printf("times faster than real-time: %f\n(%f seconds of speech synthesized in %f)\n", durs/(float)(time_end-time_start), durs, (float)(time_end-time_start)); if (flite_loop || (flite_bench && bench_iter++ < ITER_MAX)) goto loop; delete_features(extra_feats); UNREGISTER_VOX(v); return 0; }
int main(int argc, char **argv) { cst_voice *v; const char *filename; const char *outtype; int i; float durs; int flite_verbose, flite_loop, flite_bench; int explicit_filename, explicit_text, explicit_phones; #define ITER_MAX 3 int bench_iter = 0; cst_features *extra_feats; InitThreads(HT_NOMONITOR); // enable msg driven monitoring if(InitShell(argc,argv,version)<SUCCESS) return FAIL; InitMem(); InitLabel(); InitMath(); InitSigP(); InitUtil(); InitWave(); InitAudio(); filename = 0; outtype = "play"; /* default is to play */ flite_verbose = FALSE; flite_loop = FALSE; flite_bench = FALSE; explicit_text = explicit_filename = explicit_phones = FALSE; extra_feats = new_features(); flite_init(); for (i=1; i<argc; i++) { if (cst_streq(argv[i],"--version")) { flite_version(); return 1; } else if (cst_streq(argv[i],"-h") || cst_streq(argv[i],"--help") || cst_streq(argv[i],"-?")) flite_usage(); else if (cst_streq(argv[i],"-v")) flite_verbose = TRUE; else if (cst_streq(argv[i],"-l")) flite_loop = TRUE; else if (cst_streq(argv[i],"-b")) { flite_bench = TRUE; break; /* ignore other arguments */ } else if ((cst_streq(argv[i],"-o")) && (i+1 < argc)) { outtype = argv[i+1]; i++; } else if (cst_streq(argv[i],"-f") && (i+1 < argc)) { filename = argv[i+1]; explicit_filename = TRUE; i++; } else if ((cst_streq(argv[i],"-set") || cst_streq(argv[i],"-s")) && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],0); i++; } else if (cst_streq(argv[i],"--seti") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"int"); i++; } else if (cst_streq(argv[i],"--setf") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"float"); i++; } else if (cst_streq(argv[i],"--sets") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"string"); i++; } else if (cst_streq(argv[i],"-p") && (i+1 < argc)) { filename = argv[i+1]; explicit_phones = TRUE; i++; } else if (cst_streq(argv[i],"-t") && (i+1 < argc)) { filename = argv[i+1]; explicit_text = TRUE; i++; } else if (filename) outtype = argv[i]; else filename = argv[i]; } if (filename == NULL) filename = "-"; /* stdin */ v = register_cmu_us_kal16(NULL); feat_copy_into(extra_feats,v->features); durs = 0.0; if (flite_bench) { outtype = "none"; filename = "A whole joy was reaping, but they've gone south, you should fetch azure mike."; explicit_text = TRUE; } loop: if (explicit_phones) durs = flite_phones_to_speech(filename,v,outtype); else if ((strchr(filename,' ') && !explicit_filename) || explicit_text) durs = flite_text_to_speech(filename,v,outtype); else durs = flite_file_to_speech(filename,v,outtype); if (flite_loop || (flite_bench && bench_iter++ < ITER_MAX)) goto loop; delete_features(extra_feats); unregister_cmu_us_kal16(v); return 0; }
int main(int argc, char **argv) { struct timeval tv; cst_voice *v; const char *filename; const char *outtype; cst_voice *desired_voice = 0; const char *voicedir = NULL; int i; float durs; double time_start, time_end; int flite_verbose, flite_loop, flite_bench; int explicit_filename, explicit_text, explicit_phones, ssml_mode; #define ITER_MAX 3 int bench_iter = 0; cst_features *extra_feats; const char *lex_addenda_file = NULL; const char *voicedumpfile = NULL; cst_audio_streaming_info *asi; filename = 0; outtype = "play"; /* default is to play */ flite_verbose = FALSE; flite_loop = FALSE; flite_bench = FALSE; explicit_text = explicit_filename = explicit_phones = FALSE; ssml_mode = FALSE; extra_feats = new_features(); flite_init(); flite_add_lang("eng",usenglish_init,cmu_lex_init); for (i=1; i<argc; i++) { if (cst_streq(argv[i],"--version")) { flite_version(); return 1; } else if (cst_streq(argv[i],"-h") || cst_streq(argv[i],"--help") || cst_streq(argv[i],"-?")) flite_usage(); else if (cst_streq(argv[i],"-v")) flite_verbose = TRUE; else if (cst_streq(argv[i],"-lv")) { if (flite_voice_list == NULL) flite_set_voice_list(voicedir); flite_voice_list_print(); exit(0); } else if (cst_streq(argv[i],"-l")) flite_loop = TRUE; else if (cst_streq(argv[i],"-b")) { flite_bench = TRUE; break; /* ignore other arguments */ } else if ((cst_streq(argv[i],"-o")) && (i+1 < argc)) { outtype = argv[i+1]; i++; } else if ((cst_streq(argv[i],"-voice")) && (i+1 < argc)) { if (flite_voice_list == NULL) flite_set_voice_list(voicedir); desired_voice = flite_voice_select(argv[i+1]); i++; } else if ((cst_streq(argv[i],"-voicedir")) && (i+1 < argc)) { voicedir = argv[i+1]; if (flite_voice_list == NULL) flite_set_voice_list(voicedir); i++; } else if ((cst_streq(argv[i],"-add_lex")) && (i+1 < argc)) { lex_addenda_file = argv[i+1]; i++; } else if (cst_streq(argv[i],"-f") && (i+1 < argc)) { filename = argv[i+1]; explicit_filename = TRUE; i++; } else if (cst_streq(argv[i],"-pw")) { feat_set_string(extra_feats,"print_info_relation","Word"); feat_set(extra_feats,"post_synth_hook_func", uttfunc_val(&print_info)); } else if (cst_streq(argv[i],"-ps")) { feat_set_string(extra_feats,"print_info_relation","Segment"); feat_set(extra_feats,"post_synth_hook_func", uttfunc_val(&print_info)); } else if (cst_streq(argv[i],"-ssml")) { ssml_mode = TRUE; } else if (cst_streq(argv[i],"-pr") && (i+1 < argc)) { feat_set_string(extra_feats,"print_info_relation",argv[i+1]); feat_set(extra_feats,"post_synth_hook_func", uttfunc_val(&print_info)); i++; } else if (cst_streq(argv[i],"-voicedump") && (i+1 < argc)) { voicedumpfile = argv[i+1]; i++; } else if ((cst_streq(argv[i],"-set") || cst_streq(argv[i],"-s")) && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],0); i++; } else if (cst_streq(argv[i],"--seti") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"int"); i++; } else if (cst_streq(argv[i],"--setf") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"float"); i++; } else if (cst_streq(argv[i],"--sets") && (i+1 < argc)) { ef_set(extra_feats,argv[i+1],"string"); i++; } else if (cst_streq(argv[i],"-p") && (i+1 < argc)) { filename = argv[i+1]; explicit_phones = TRUE; i++; } else if (cst_streq(argv[i],"-t") && (i+1 < argc)) { filename = argv[i+1]; explicit_text = TRUE; i++; } else if (filename) outtype = argv[i]; else filename = argv[i]; } if (filename == NULL) filename = "-"; /* stdin */ if (flite_voice_list == NULL) flite_set_voice_list(voicedir); if (desired_voice == 0) desired_voice = flite_voice_select(NULL); v = desired_voice; feat_copy_into(extra_feats,v->features); durs = 0.0; if (voicedumpfile != NULL) { flite_voice_dump(v,voicedumpfile); exit(0); } if (lex_addenda_file) flite_voice_add_lex_addenda(v,lex_addenda_file); if (cst_streq("stream",outtype)) { asi = new_audio_streaming_info(); asi->asc = audio_stream_chunk; feat_set(v->features,"streaming_info",audio_streaming_info_val(asi)); } if (flite_bench) { outtype = "none"; filename = "A whole joy was reaping, but they've gone south, you should fetch azure mike."; explicit_text = TRUE; } loop: gettimeofday(&tv,NULL); time_start = (double)(tv.tv_sec)+(((double)tv.tv_usec)/1000000.0); if (explicit_phones) durs = flite_phones_to_speech(filename,v,outtype); else if ((strchr(filename,' ') && !explicit_filename) || explicit_text) { if (ssml_mode) durs = flite_ssml_text_to_speech(filename,v,outtype); else durs = flite_text_to_speech(filename,v,outtype); } else { if (ssml_mode) durs = flite_ssml_file_to_speech(filename,v,outtype); else durs = flite_file_to_speech(filename,v,outtype); } gettimeofday(&tv,NULL); time_end = ((double)(tv.tv_sec))+((double)tv.tv_usec/1000000.0); if (flite_verbose || (flite_bench && bench_iter == ITER_MAX)) printf("times faster than real-time: %f\n(%f seconds of speech synthesized in %f)\n", durs/(float)(time_end-time_start), durs, (float)(time_end-time_start)); if (flite_loop || (flite_bench && bench_iter++ < ITER_MAX)) goto loop; delete_features(extra_feats); delete_val(flite_voice_list); flite_voice_list=0; /* cst_alloc_debug_summary(); */ return 0; }
int main(int argc, char **argv) { bard_reader *br; cst_features *args; cst_features *config; float idle_time; int spos; args = new_features(); cst_args(argv,argc, "usage: bard OPTIONS\n" "Bard Storyteller\n" "-text <string> Text filename to read\n" "-text_pos <int> Starting position in text file\n" "-config_file <string> Override default config file ($HOME/.bard_config)\n" "-font <string> Pathname to ttf font file\n" "-font_size <int> Initial font size\n" "-audio_method <string> SDL or flite\n" "-voice <string> Voice name (or pathname to dumped voice)\n" "-audio_stream_buffer_factor <int> Bigger for slower processors\n" "-gain <float> Volume factor (1.0 is default)\n" "-speed <float> Duration stretch (inverse speed)\n" "-battery_script <string> Script to get battery charge state\n" "-screen_height <int> \n" "-screen_width <int> \n" "-screen_blank_idle_time <float> In secs (0 means no blanking)\n" "-scroll_delay <int> In ms\n" "-voices_dir <string> Directory containing *.flitevox voices\n" "-debug <int> Print debug messages\n" "", args); /* If text specified and no position given, start from 0 */ if (feat_present(args,"-text") && !feat_present(args,"-text_pos")) feat_set_int(args,"-text_pos",0); if (!feat_present(args,"-font")) feat_set_string(args,"-font",BARD_DEFAULT_FONT); bard_debug = get_param_int(args,"-debug",0); config = bard_read_config(args); cst_feat_print(stdout,config); br = bard_open(config); if (br == NULL) return -1; /* something went really wrong */ /* Make the windows */ br->text = bard_make_text_window(br); br->file_select = bard_make_file_select_window(br); br->info = bard_make_info_window(br); /* general info/params */ br->help = bard_make_help_window(br); br->recent = bard_make_recent_window(br); br->menu = bard_make_menu_window(br); if (feat_present(br->config,"-voices_dir")) br->voice_select = bard_make_voice_select_window(br); /* Select focus */ br->display->current = br->text; bard_display_clear(br->display); bard_display_update(br->display); bard_screen_on(NULL); /* just in case it is currently off */ while (br->quit == 0) { if (input_process_events(br) == 0) { if (br->scroll) { SDL_Delay(br->scroll_delay); /* no key press but scrolling */ br->quiet_time = SDL_GetTicks(); /* no blank while scrolling */ } else SDL_Delay(br->no_key_delay); /* no key press, so pause a bit */ } if (br->speak == 1) { /* Within the audio callback function, we also call */ /* input_process_events so we can stop if requested */ br->pause = 0; if (br->display->current->current_token) spos = br->display->current->current_token->file_pos; else spos = br->display->current->sop_pos; /* We need spos-1 here to make it display well */ bard_speak_text(br->speech,br->display->current->textfile,spos-1); br->speak = 0; br->quiet_time = SDL_GetTicks(); } else if (br->scroll) { /* Speaking and smooth scrolling are mutually exclusive */ if (bard_text_scroll(br->text) == 0) br->scroll = 0; /* Reached end of file so stop scroll */ bard_display_update(br->display); /* Update screen */ } else br->text->scroll_offset = 0; /* Check if we should black/hide cursor */ idle_time = (SDL_GetTicks()-br->quiet_time)/1000.0; if ((br->screen_blank_idle_time > 0) && (idle_time > br->screen_blank_idle_time) && (br->blank == 0)) { br->blank = 1; bard_screen_off(NULL); } idle_time = (SDL_GetTicks()-br->mouse_quiet_time)/1000.0; if (idle_time > 5.0) SDL_ShowCursor(SDL_DISABLE); } /* Save context */ bard_write_config(br); bard_close(br); delete_features(args); return 0; }