Exemple #1
0
/*--------------------------------------------------------------------
 * setup
 *--------------------------------------------------------------------*/
void flite_setup(void) {
  post("");
  post(flite_description);
  post("");

  // --- setup synth
  flite_init();
  voice = PDFLITE_REGISTER_VOICE();

  // --- register class
  flite_class = class_new(gensym("flite"),
			  (t_newmethod)flite_new,  // newmethod
			  (t_method)flite_free,    // freemethod
			  sizeof(t_flite),         // size
			  CLASS_DEFAULT,           // flags
			  A_DEFSYM,                // arg1: table-name
			  0);

  // --- class methods
  class_addlist(flite_class, flite_list);
  class_addmethod(flite_class, (t_method)flite_set,   gensym("set"),   A_DEFSYM, 0);
  class_addmethod(flite_class, (t_method)flite_text,  gensym("text"),  A_GIMME, 0);
  class_addmethod(flite_class, (t_method)flite_synth, gensym("synth"), 0);

  // --- help patch
  //class_sethelpsymbol(flite_class, gensym("flite-help.pd")); /* breaks pd-extended help lookup */
}
Exemple #2
0
bool stardict_tts_plugin_init(StarDictTtsPlugInObject *obj)
{
	flite_init();

	register_cmu_us_kal(NULL);
	register_cmu_time_awb(NULL);
	register_cmu_us_kal16(NULL);
	register_cmu_us_awb(NULL);
	register_cmu_us_rms(NULL);
	register_cmu_us_slt(NULL);

	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[flite]\nvoice=\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	gchar *str = g_key_file_get_string(keyfile, "flite", "voice", NULL);
	g_key_file_free(keyfile);
	if (str) {
		voice_engine = str;
		g_free(str);
	}
	if (!voice_engine.empty()) {
		now_voice = flite_voice_select(voice_engine.c_str());
	} else {
		now_voice = flite_voice_select(NULL);
	}
	obj->saytext_func = saytext;
	obj->tts_name = _("Flite TTS");
	g_print(_("Flite plug-in loaded.\n"));
	return false;
}
static PyObject* PySemsAudioFile_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    DBG("---------- PySemsAudioFile_alloc -----------\n");
    PySemsAudioFile *self;

    self = (PySemsAudioFile *)type->tp_alloc(type, 0);

    if (self != NULL) {

        self->af = new AmAudioFile();
        if(!self->af) {
            Py_DECREF(self);
            return NULL;
        }

#ifdef IVR_WITH_TTS
        flite_init();
        self->tts_voice = register_cmu_us_kal();
        self->filename = new string();
#endif

    }

    return (PyObject *)self;
}
Exemple #4
0
static int save_dataset_comments (const dataset *dset)
{
    int i, j;
    cst_voice *v;
    cst_wave *w, *fullw = NULL;

    flite_init();
    v = register_cmu_us_kal();

    j = 0;
    for (i=0; i<N_COMMENTS; i++) {
	if (dset->comments[i] != NULL) {
	    if (j == 0) {
		fullw = flite_text_to_wave(dset->comments[i], v);
	    } else {
		w = flite_text_to_wave(dset->comments[i], v);
		concat_wave(fullw, w);
		delete_wave(w);
	    }
	    j++;
	}
    }

    cst_wave_save_riff(fullw, "gretl_flite.wav");
    delete_wave(fullw);

    return 0;
}
void *tell_us_the_position(void *threadid)
{
	cst_voice *v;
	char choise[2];
	char text_to_speech[MAX_TEXT_TO_SPEECH];
	unsigned int current_position;
	signed int degree_difference;
	signed char pich,roll;
	unsigned char should_speaks_the_route = 0;

	// Init TTS system
	flite_init();
	// Choose language
	v=register_irstifd_ita_pc();
	
	sprintf(text_to_speech,"Fred, versione %s",VERSION);
	flite_text_to_speech(text_to_speech,v,"play");
	flite_text_to_speech("Il sistema è pronto",v,"play");
	while(1)
	{

		int ret = read(PIPE_CHANNEL[0], choise, 1);
		if(ret > 0)
		{
			read_compass_global_var(&current_position,&pich,&roll);
			if(choise[0] == '1') sprintf(text_to_speech,"Posizione %i",current_position);
			if(choise[0] == '2') sprintf(text_to_speech,"Beccheggio %i",pich);
			if(choise[0] == '3') sprintf(text_to_speech,"Rollio %i",roll);
			if(choise[0] == '4')
			{
				sprintf(text_to_speech,"Posizione di partenza impostanta a %i",current_position);
				START_POSITION = current_position;
				should_speaks_the_route = 1;
			}			
			// Exit request
			if(choise[0] == '5') break;
			// Text to speech
			flite_text_to_speech(text_to_speech,v,"play");
		}

		// Check for periodic announcement
		if(should_speaks_the_route == 1) 
		{
			if(is_time_to_speak())
			{
				degree_difference = speaks_route();
				if(degree_difference != 0)
				{
					sprintf(text_to_speech,"Fuori rotta di %i",degree_difference);
					flite_text_to_speech(text_to_speech,v,"play");
				}
			}
		}
	}
	flite_text_to_speech("Richiesta uscita programma",v,"play");
	flite_text_to_speech("Fred vi saluta, ciao",v,"play");
	// End thread
	pthread_exit(NULL);
}
Exemple #6
0
int main(int argc, char** argv)
{
    flite_init();

    v=register_cmu_us_kal16();
    flite_text_to_speech("Hello world",v,"play");
    printf ("Finished \n");

    exit(0);
}
Exemple #7
0
int main(int argc, char** argv)
{
    flite_init();

    v=register_cmu_time_awb();
    flite_text_to_speech("11:52 PM",v,"flite_test.wav");
    printf ("Finished \n");

    exit(0);
}
Exemple #8
0
static gboolean
plugin_init (GstPlugin * plugin)
{
  flite_init ();

  gst_element_register (plugin, "flitetestsrc", GST_RANK_NONE,
      gst_flite_test_src_get_type ());

  return TRUE;
}
Exemple #9
0
static int fl_init(char **status_info)
{
	int ret;
	GString *info;

	log_msg(OTTS_LOG_INFO, "Module init");
	*status_info = NULL;
	info = g_string_new("");

	/* Init flite and register a new voice */
	flite_init();
	flite_voice = register_cmu_us_kal();

	if (flite_voice == NULL) {
		log_msg(OTTS_LOG_ERR,
			"Couldn't register the basic kal voice.\n");
		*status_info =
		    g_strdup("Can't register the basic kal voice. "
			     "Currently only kal is supported. Seems your FLite "
			     "installation is incomplete.");
		return -1;
	}

	log_msg(OTTS_LOG_DEBUG, "FliteMaxChunkLength = %d\n",
		FliteMaxChunkLength);
	log_msg(OTTS_LOG_DEBUG, "FliteDelimiters = %s\n", FliteDelimiters);

	flite_message = g_malloc(sizeof(char *));
	*flite_message = NULL;

	flite_semaphore = module_semaphore_init();

	log_msg(OTTS_LOG_INFO, "Flite: creating new thread for flite_speak\n");
	flite_speaking = 0;
	ret = pthread_create(&flite_speak_thread, NULL, _flite_speak, NULL);
	if (ret != 0) {
		log_msg(OTTS_LOG_ERR, "Flite: thread failed\n");
		*status_info =
		    g_strdup("The module couldn't initialize threads "
			     "This could be either an internal problem or an "
			     "architecture problem. If you are sure your architecture "
			     "supports threads, please report a bug.");
		return -1;
	}

	module_audio_id = NULL;

	*status_info = g_strdup("Flite initialized successfully.");

	return 0;
}
Exemple #10
0
static void speak_dataset_comments (const dataset *dset)
{
    int i;
    cst_voice *v;

    flite_init();
    v = register_cmu_us_kal();

    for (i=0; i<N_COMMENTS; i++) {
	if (dset->comments[i] != NULL) {
	    flite_text_to_speech(dset->comments[i], v, "play");
	}
    }
}
Exemple #11
0
static int speak_line (const char *line)
{
    static cst_voice *v;

    if (v == NULL) {
        flite_init();
        v = register_cmu_us_kal();
    }

    if (v == NULL) return 1;

    flite_text_to_speech(line, v, "play");

    return 0;
}
Exemple #12
0
void init()
{
    PaError err;
    if (paNoError != (err = Pa_Initialize())) 
    {
        fprintf(stderr, "Cannot initialize PortAudio: %s\n", Pa_GetErrorText(err));
        exit(-1);
    }

    si.w = NULL;
    si.pos = 0;

    flite_init();
    voice = VOICE();
    CHECK_NULL(voice, "cannot open voice");
}
Exemple #13
0
int main(int argc, char **argv)
{
    cst_voice *v;
    char thetime[1024];
    char b[3];
    int hour, min;
    cst_regex *timex;
    char *output = "play";

    if (argc != 2)
    {
	fprintf(stderr,"usage: flite_time HH:MM\n");
	exit(-1);
    }
    timex =  new_cst_regex("[012][0-9]:[0-5][0-9]");
    if (!cst_regex_match(timex,argv[1]))
    {
	fprintf(stderr,"not a valid time\n");
	fprintf(stderr,"usage: flite_time HH:MM\n");
	exit(-1);
    }
    delete_cst_regex(timex);
    b[2] = '\0';
    b[0] = argv[1][0];
    b[1] = argv[1][1];
    hour = atoi(b);
    b[0] = argv[1][3];
    b[1] = argv[1][4];
    min = atoi(b);

    flite_init();

    v = register_cmu_time_awb(NULL);

    sprintf(thetime,
	    "The time is now, %s %s %s, %s.",
	    time_approx(hour,min),
	    time_min(hour,min),
	    time_hour(hour,min),
	    time_tod(hour,min));

    printf("%s\n",thetime);
    flite_text_to_speech(thetime,v,output);

    return 0;
}
Exemple #14
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{

    flite_init();

    cst_voice *v1 = register_cmu_us_rms(NULL);
    cst_voice *v2 = register_cmu_us_slt(NULL);
    for(int i = 0; i < 3; ++i)
    {
        flite_text_to_speech("Welcome to the testing facility", v1, "play");
        ::Beep( 1000, 800);

        flite_text_to_speech("Welcome to the testing facility", v2, "play");
        ::Beep( 1000, 800);
    }
}
Exemple #15
0
int __init fimc_md_init(void)
{
	int ret;

	request_module("s5p-csis");
	ret = fimc_register_driver();
	if (ret)
		return ret;
#ifdef CONFIG_VIDEO_EXYNOS_FIMC_IS 
	ret = fimc_is_init();
	if (ret)
		return ret;
#endif
#ifdef CONFIG_VIDEO_EXYNOS_FIMC_LITE
	ret = flite_init();
	if (ret)
		return ret;
#endif

	return platform_driver_register(&fimc_md_driver);
}
void flowm_init()
{
#ifdef DOTTS
    int i;
    cst_audio_streaming_info *asi;

    flite_init();        /* Initialize flite interface */

    for (i=0; VoxDefs[i].name; i++)
    {
        VoxDefs[i].v = (VoxDefs[i].rv)(NULL); /* register voice */

        /* Set up call back function for low level audio streaming */
        /* This way it plays the waveform as it synthesizes it */
        /* This is necessary for the slower (CG) voices */
        asi = new_audio_streaming_info();
        asi->asc = flowm_audio_stream_chunk;
        asi->min_buffsize = VoxDefs[i].min_buffsize;
        feat_set(VoxDefs[i].v->features,
                 "streaming_info",
                 audio_streaming_info_val(asi));

        /* Set up call back function for sending what tokens are being */
        /* synthesized and for keeping track of the current position in */
        /* the file */
        feat_set(VoxDefs[i].v->features,
                 "utt_user_callback",
                 uttfunc_val(flowm_utt_callback));

        /* For outputing results of a relation (only used in play) */
        feat_set(VoxDefs[i].v->features,
                 "post_synth_hook_func",
                 uttfunc_val(flowm_print_relation_callback));
    }

#endif
    return;
}
Exemple #17
0
static int speak_buffer (const char *buf, int (*should_stop)())
{
    cst_voice *v;
    char line[2048];

    flite_init();
    v = register_cmu_us_kal();

    bufgets_init(buf);

    while (bufgets(line, sizeof line, buf)) {
        if (should_stop()) {
            flite_text_to_speech("OK, stopping", v, "play");
            break;
        }
        tailstrip(line);
        flite_text_to_speech(line, v, "play");
    }

    bufgets_finalize(buf);

    return 0;
}
    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;
    }
Exemple #19
0
static void audio_graph_error (const char *msg)
{
#ifdef HAVE_FLITE
    cst_voice *v;
#endif
#ifdef WIN32_SAPI
    ISpVoice *v = NULL;
    HRESULT hr;
#endif    

    fprintf(stderr, "%s\n", msg);

#ifdef HAVE_FLITE
    flite_init();

    v = register_cmu_us_kal();
    flite_text_to_speech(msg, v, "play");
#endif
#ifdef WIN32_SAPI
    hr = CoInitialize(NULL);
    if (!SUCCEEDED(hr)) return;

    hr = CoCreateInstance(&CLSID_SpVoice, 
                          NULL, 
                          CLSCTX_ALL, 
                          &IID_ISpVoice, 
                          (void *) &v);
    if (SUCCEEDED(hr)) {
	wchar_t *w = wide_string(msg);

	ISpVoice_Speak(v, w, 0, NULL);
	free(w);
        ISpVoice_Release(v);
    } 
#endif
}
Exemple #20
0
Reader::Reader()
{
	flite_init();
	m_ptrVoice = register_cmu_us_rms( NULL );
}
Exemple #21
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;
}
Exemple #22
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;
}
Exemple #23
0
static void FlopSpeakCmd(UInt16 formID, UInt16 ifieldID, UInt16 ofieldID)
{
    FormPtr frm;
    FieldPtr fld;
    UInt16 obj;
    CharPtr p;
    VoidHand h;
    UInt32 processor_type;
    const char *ch=NULL;
    
    frm = FrmGetFormPtr(formID);
    obj = FrmGetObjectIndex(frm, ifieldID);
    fld = (FieldPtr)FrmGetObjectPtr(frm, obj);
    h = (VoidHand)FldGetTextHandle(fld);
    p = (CharPtr)MemHandleLock(h);

    /* Check we are on an ARM */
    FtrGet(sysFileCSystem, sysFtrNumProcessorID, &processor_type);
    if (processor_type == sysFtrNumProcessorx86)
	ch = "Flite doesn't run on the emulator";
    else if (!sysFtrNumProcessorIsARM(processor_type))
	ch = "Flite requires an ARM processor";
    else
    {   /* We're on an ARM -- so setup flite */
	if (!flite) 
	{
	    flite = flite_init();
	    if (flite == 0)
		ch = "Flite failed to initialize";
	    else
	    {
		flite->PlayPosition = 0;
		flite->output = output;
		flite->max_output = FlopMaxOutputChars;
		ch = flite->output;
	    }
	}

	if (FlopPlay == false)
	{
	    FlopPlay = true;
	    StrPrintF(input,"%s",p);
	    if (flite->utt_length == 0)
		flite->start = 0;
	    /* toggle play/stop button to play */
	}
	else
	{
	    FlopPlay = false;
	    flite->start = flite->PlayPosition;
	    /* toggle play/stop button to stop */
	}
    }

    if (ch)
    {
	/* Update the output field with any new information */
	SetField(FlopForm, FlopOutput, ch);
	FrmDrawForm(FrmGetFormPtr(FlopForm));
    }

    MemHandleUnlock(h);
}
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;
}