Exemple #1
0
float flite_process_output(cst_utterance *u, const char *outtype,
                           int append)
{
    /* Play or save (append) output to output file */
    cst_wave *w;
    float dur;

    if (!u) return 0.0;

    w = utt_wave(u);

    dur = (float)w->num_samples/(float)w->sample_rate;
	     
    if (cst_streq(outtype,"play"))
	play_wave(w);
    else if (cst_streq(outtype,"stream"))
    {
        /* It's already been played so do nothing */
        
    }
    else if (!cst_streq(outtype,"none"))
    {
        if (append)
            cst_wave_append_riff(w,outtype);
        else
            cst_wave_save_riff(w,outtype);
    }

    return dur;
}
cst_wave *flite_text_to_wave(const char *text, cst_voice *voice)
{
    cst_utterance *u;
    cst_wave *w;

    if ((u = flite_synth_text(text,voice)) == NULL)
	return NULL;

    w = copy_wave(utt_wave(u));
    delete_utterance(u);
    return w;
}
float flite_tokens_to_speech(cst_utterance *u,
			     cst_voice *voice,
			     const char *outtype)
{
    cst_wave *w;
    float durs;

    u = flite_synth_foo(u,voice,utt_synth_tokens);
    if (u == NULL)
	    return -1;
    w = utt_wave(u);

    durs = (float)w->num_samples/(float)w->sample_rate;

    if (cst_streq(outtype,"play"))
	play_wave(w);
    else if (!cst_streq(outtype,"none"))
	cst_wave_append_riff(w,outtype);
    delete_utterance(u);

    return durs;
}
Exemple #4
0
int main(int argc, char *argv[])
{
   char *s,*fn;
   cst_voice *voice;     // synthesis voice
   cst_utterance *utt;   // current utterance
   cst_wave *cstwave;       // synthesised wave
   Wave w;  // HTK wave
   short *p;
   HTime sampPeriod = 625.0;
   int n;
   MemHeap mem;
   AudioOut a;

   try {
      if (InitHTK(argc,argv,version)<SUCCESS){
         ReportErrors("Main",0); exit(-1);
      }
      if (NumArgs() !=2) {
         printf("SFliteTest synthstring file\n"); exit(0);
      }
      CreateHeap(&mem,"heap",MSTAK,1,0.0,10000,100000);
      s = GetStrArg();
      fn = GetStrArg();
      printf("Synth: %s -> %s\n",s,fn);
      // initialise Edinburgh cst lib
      cst_regex_init();
      // setup the voice
      voice = register_cmu_us_kal16(NULL);
      // convert text to waveform
      utt = flite_synth_text(s,voice);
      if (utt==NULL) {
         HRError(12001,"SFliteTest: cant synthesise %s\n",s);
         throw ATK_Error(12001);
      }
      cstwave = utt_wave(utt);
      p = cstwave->samples; n = cstwave->num_samples;
      w = OpenWaveOutput(&mem,&sampPeriod,n);
      printf("%d samples created\n",n);
      PutWaveSample(w,n,p);
      if (CloseWaveOutput(w,WAV,fn)<SUCCESS){
         ReportErrors("Main",0); exit(-1);
      }
      // explore structure
      const cst_item *it, *itlast = NULL;
      float x,y;
      int i;
      string lastword="0"; x = 0;
      for (i=1,it = relation_head(utt_relation(utt, "Segment")); it!=NULL; it = item_next(it),i++)
      {
         printf("Segment %d\n",i);
         y = item_feat_float(it,"end");
         string ph = string(ffeature_string(it,"p.name"));
         string wd = string(ffeature_string(it,"R:SylStructure.parent.parent.name"));
         //printf("end = %f ph=%s wd=%s\n",y,ph.c_str(),wd.c_str());
         if (wd != lastword){
            printf("**** end of %s = %f\n",lastword.c_str(),x);
            lastword=wd;
         }
         x = y;
      }
      //if (itlast!=NULL) {
      //   word = string(ffeature_string(itlast,"R:SylStructure.parent.parent.name"));
      //   idx = text.find(word);
      //}


      return 0;
   }



   catch (ATK_Error e){ ReportErrors("ATK",e.i); }
   catch (HTK_Error e){ ReportErrors("HTK",e.i); }
   return 0;
}