コード例 #1
0
ファイル: flite.c プロジェクト: thenoiseindex/convergence
float flite_file_to_speech(const char *filename, 
			   cst_voice *voice,
			   const char *outtype)
{
    cst_utterance *utt;
    cst_tokenstream *ts;
    const char *token;
    cst_item *t;
    cst_relation *tokrel;
    float durs = 0;
    int num_tokens;
    cst_wave *w;
    cst_breakfunc breakfunc = default_utt_break;
    cst_uttfunc utt_user_callback = 0;
    int fp;

    if ((ts = ts_open(filename,
	      get_param_string(voice->features,"text_whitespace",NULL),
	      get_param_string(voice->features,"text_singlecharsymbols",NULL),
	      get_param_string(voice->features,"text_prepunctuation",NULL),
	      get_param_string(voice->features,"text_postpunctuation",NULL)))
	== NULL)
    {
	cst_errmsg("failed to open file \"%s\" for reading\n",
		   filename);
	return 1;
    }
    fp = get_param_int(voice->features,"file_start_position",0);
    if (fp > 0)
        ts_set_stream_pos(ts,fp);

    if (feat_present(voice->features,"utt_break"))
	breakfunc = val_breakfunc(feat_val(voice->features,"utt_break"));

    if (feat_present(voice->features,"utt_user_callback"))
	utt_user_callback = val_uttfunc(feat_val(voice->features,"utt_user_callback"));

    /* If its a file to write to, create and save an empty wave file */
    /* as we are going to incrementally append to it                 */
    if (!cst_streq(outtype,"play") && 
        !cst_streq(outtype,"none") &&
        !cst_streq(outtype,"stream"))
    {
	w = new_wave();
	cst_wave_resize(w,0,1);
	cst_wave_set_sample_rate(w,16000);
	cst_wave_save_riff(w,outtype);  /* an empty wave */
	delete_wave(w);
    }

    num_tokens = 0;
    utt = new_utterance();
    tokrel = utt_relation_create(utt, "Token");
    while (!ts_eof(ts) || num_tokens > 0)
    {
	token = ts_get(ts);
	if ((cst_strlen(token) == 0) ||
	    (num_tokens > 500) ||  /* need an upper bound */
	    (relation_head(tokrel) && 
	     breakfunc(ts,token,tokrel)))
	{
	    /* An end of utt, so synthesize it */
            if (utt_user_callback)
                utt = (utt_user_callback)(utt);

            if (utt)
            {
                utt = flite_do_synth(utt,voice,utt_synth_tokens);
                durs += flite_process_output(utt,outtype,TRUE);
                delete_utterance(utt); utt = NULL;
            }
            else 
                break;

	    if (ts_eof(ts)) break;

	    utt = new_utterance();
	    tokrel = utt_relation_create(utt, "Token");
	    num_tokens = 0;
	}
	num_tokens++;

	t = relation_append(tokrel, NULL);
	item_set_string(t,"name",token);
	item_set_string(t,"whitespace",ts->whitespace);
	item_set_string(t,"prepunctuation",ts->prepunctuation);
	item_set_string(t,"punc",ts->postpunctuation);
        /* Mark it at the beginning of the token */
	item_set_int(t,"file_pos",
                     ts->file_pos-(1+ /* as we are already on the next char */
                                   cst_strlen(token)+
                                   cst_strlen(ts->prepunctuation)+
                                   cst_strlen(ts->postpunctuation)));
	item_set_int(t,"line_number",ts->line_number);
    }

    delete_utterance(utt);
    ts_close(ts);
    return durs;
}
コード例 #2
0
ファイル: lpc_resynth_main.c プロジェクト: HeinzSchmidt/mimic
int main(int argc, char **argv)
{
    cst_track *t1;
    cst_track *me_filters = NULL;
    cst_wave *w1, *w2, *res = NULL;
    cst_val *files;
    cst_features *args;
    int i, j;
    int order, o, s;
    int frame_length;
    float *lpcs, *residual;
    float m;
    const char *f1, *f2;
    const char *resfn = NULL;
    int last_peak = 0, next_peak;
    int period;
    float power;
    int rfc = 0;
    int str = 0;
    int fn, fo, ss;
    float xpulse, xnoise;
    float fxpulse, fxnoise;
    float x, me;
    float *hpulse = NULL, *hnoise = NULL;
    float *xpulsesig = NULL, *xnoisesig = NULL;
    int q = 0;
    int position;
    int lpc_start = 0;

    args = new_features();
    files =
        cst_args(argv, argc,
                 "usage: lpc_resynth OPTIONS INTRACK OUTWAVE\n"
                 "Resynth an lpc track\n"
                 "-res <string> residual (as waveform)\n"
                 "-save_res Save the generated residual\n"
                 "-lpc_start <int> start of lpc params in lpc track {1}\n"
                 "-order <int> LPC order {16}\n"
                 "-str mixed excitation strengths\n"
                 "-me_filters <string> mixed excitation filters\n"
                 "-rfc Coefficents are reflection coefficients\n", args);

    f1 = val_string(val_car(files));
    f2 = val_string(val_car(val_cdr(files)));
    t1 = new_track();

    lpc_start = mimic_get_param_int(args, "-lpc_start", 1);
    if (feat_present(args, "-rfc"))
        rfc = 1;
    if (feat_present(args, "-str"))
        str = 1;
    if (feat_present(args, "-me_filters"))
    {
        me_filters = new_track();
        if (cst_track_load_est
            (me_filters,
             mimic_get_param_string(args, "-me_filters",
                                    "me_filters.track")) != CST_OK_FORMAT)
        {
            fprintf(stderr,
                    "lpc_resynth: can't read file or wrong format \"%s\"\n",
                    f1);
            return -1;
        }
        hpulse = cst_alloc(float, me_filters->num_channels);
        hnoise = cst_alloc(float, me_filters->num_channels);
        xpulsesig = cst_alloc(float, me_filters->num_channels);
        xnoisesig = cst_alloc(float, me_filters->num_channels);
    }
コード例 #3
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;
}