Exemplo n.º 1
0
void TextToSpeech::synthesis(char *txt, FILE * wavfp)
{
	char buff[MAXBUFLEN];

	text2mecab(buff, txt);
	Mecab_analysis(&open_jtalk_.mecab, buff);
	mecab2njd(&open_jtalk_.njd, Mecab_get_feature(&open_jtalk_.mecab), Mecab_get_size(&open_jtalk_.mecab));
	njd_set_pronunciation(&open_jtalk_.njd);
	njd_set_digit(&open_jtalk_.njd);
	njd_set_accent_phrase(&open_jtalk_.njd);
	njd_set_accent_type(&open_jtalk_.njd);
	njd_set_unvoiced_vowel(&open_jtalk_.njd);
	njd_set_long_vowel(&open_jtalk_.njd);
	njd2jpcommon(&open_jtalk_.jpcommon, &open_jtalk_.njd);
	JPCommon_make_label(&open_jtalk_.jpcommon);
	if (JPCommon_get_label_size(&open_jtalk_.jpcommon) > 2) {
		HTS_Engine_load_label_from_string_list(
			&open_jtalk_.engine,
			JPCommon_get_label_feature(&open_jtalk_.jpcommon),
			JPCommon_get_label_size(&open_jtalk_.jpcommon)
		);
		HTS_Engine_create_sstream(&open_jtalk_.engine);
		HTS_Engine_create_pstream(&open_jtalk_.engine);
		HTS_Engine_create_gstream(&open_jtalk_.engine);
		if (wavfp != NULL)
			HTS_Engine_save_riff(&open_jtalk_.engine, wavfp);
		HTS_Engine_refresh(&open_jtalk_.engine);
	}
	JPCommon_refresh(&open_jtalk_.jpcommon);
	NJD_refresh(&open_jtalk_.njd);
	Mecab_refresh(&open_jtalk_.mecab);
}
Exemplo n.º 2
0
void TextToSpeech::synthesis(const char *txt)
{
	char buff[MAXBUFLEN];

	text2mecab(buff, txt);
	Mecab_analysis(&open_jtalk_.mecab, buff);
	mecab2njd(&open_jtalk_.njd, Mecab_get_feature(&open_jtalk_.mecab), Mecab_get_size(&open_jtalk_.mecab));
	njd_set_pronunciation(&open_jtalk_.njd);
	njd_set_digit(&open_jtalk_.njd);
	njd_set_accent_phrase(&open_jtalk_.njd);
	njd_set_accent_type(&open_jtalk_.njd);
	njd_set_unvoiced_vowel(&open_jtalk_.njd);
	njd_set_long_vowel(&open_jtalk_.njd);
	njd2jpcommon(&open_jtalk_.jpcommon, &open_jtalk_.njd);
	JPCommon_make_label(&open_jtalk_.jpcommon);
	if (JPCommon_get_label_size(&open_jtalk_.jpcommon) > 2) {
		unsigned int pcm_len;
		HTS_Engine_load_label_from_string_list(
			&open_jtalk_.engine,
			JPCommon_get_label_feature(&open_jtalk_.jpcommon),
			JPCommon_get_label_size(&open_jtalk_.jpcommon)
		);
		HTS_Engine_create_sstream(&open_jtalk_.engine);
		HTS_Engine_create_pstream(&open_jtalk_.engine);
		HTS_Engine_create_gstream(&open_jtalk_.engine);
		pcm_len = HTS_Engine_get_generated_speech_size(&open_jtalk_.engine);
		pcm_ = new short[pcm_len];
		HTS_Engine_get_generated_speech(&open_jtalk_.engine, pcm_);
		play_write(play_h_, pcm_, pcm_len * sizeof(short));
		HTS_Engine_refresh(&open_jtalk_.engine);
	}
	JPCommon_refresh(&open_jtalk_.jpcommon);
	NJD_refresh(&open_jtalk_.njd);
	Mecab_refresh(&open_jtalk_.mecab);
}
Exemplo n.º 3
0
int OpenJTalk_synthesis_towav(OpenJTalk** openjtalk,const char* text, const char* wavfilename)
{
   char buff[MAXBUFLEN];
   FILE * wavfp;
   wavfp = fopen(wavfilename,"wb");
   if (!wavfp)
   {
       sprintf((*openjtalk)->errorout,"can not open %s.",wavfilename);
       return 0;
   }

   text2mecab(buff, (char*)text);
   Mecab_analysis((*openjtalk)->mecab, buff);
   mecab2njd(&(*openjtalk)->njd, Mecab_get_feature((*openjtalk)->mecab),
             Mecab_get_size((*openjtalk)->mecab));
   njd_set_pronunciation(&(*openjtalk)->njd);
   njd_set_digit(&(*openjtalk)->njd);
   njd_set_accent_phrase(&(*openjtalk)->njd);
   njd_set_accent_type(&(*openjtalk)->njd);
   njd_set_unvoiced_vowel(&(*openjtalk)->njd);
   njd_set_long_vowel(&(*openjtalk)->njd);
   njd2jpcommon(&(*openjtalk)->jpcommon, &(*openjtalk)->njd);
   JPCommon_make_label(&(*openjtalk)->jpcommon);
   if (JPCommon_get_label_size(&(*openjtalk)->jpcommon) > 2) {
      HTS_Engine_load_label_from_string_list(&(*openjtalk)->engine,
                                             JPCommon_get_label_feature(&(*openjtalk)->jpcommon),
                                             JPCommon_get_label_size(&(*openjtalk)->jpcommon));
      HTS_Engine_create_sstream(&(*openjtalk)->engine);
      HTS_Engine_create_pstream(&(*openjtalk)->engine);
      HTS_Engine_create_gstream(&(*openjtalk)->engine);

      HTS_Engine_save_riff(&(*openjtalk)->engine, wavfp);
/*
      if (wavfp != NULL)
         HTS_Engine_save_riff(&(*openjtalk)->engine, wavfp);
      if (logfp != NULL) {
         fprintf(logfp, "[Text analysis result]\n");
         NJD_fprint(&(*openjtalk)->njd, logfp);
         fprintf(logfp, "\n[Output label]\n");
         HTS_Engine_save_label(&(*openjtalk)->engine, logfp);
         fprintf(logfp, "\n");
         HTS_Engine_save_information(&(*openjtalk)->engine, logfp);
      }
*/
      HTS_Engine_refresh(&(*openjtalk)->engine);
   }
   JPCommon_refresh(&(*openjtalk)->jpcommon);
   NJD_refresh(&(*openjtalk)->njd);
   Mecab_refresh((*openjtalk)->mecab);

   fclose(wavfp);
   return 1;
}
Exemplo n.º 4
0
static int synthesize(struct app *app, char *txt)
{
	char buff[MAXBUFLEN];
	int label_size;
	int r = -1;

	text2mecab(buff, txt);
	Mecab_analysis(&app->mecab, buff);
	mecab2njd(&app->njd, Mecab_get_feature(&app->mecab),
		  Mecab_get_size(&app->mecab));
	njd_set_pronunciation(&app->njd);
	njd_set_digit(&app->njd);
	njd_set_accent_phrase(&app->njd);
	njd_set_accent_type(&app->njd);
	njd_set_unvoiced_vowel(&app->njd);
	njd_set_long_vowel(&app->njd);
	njd2jpcommon(&app->jpcommon, &app->njd);
	JPCommon_make_label(&app->jpcommon);
	label_size = JPCommon_get_label_size(&app->jpcommon);
	if (label_size > 2) {
		if (HTS_Engine_synthesize_from_strings(
				&app->engine,
				JPCommon_get_label_feature(&app->jpcommon),
				label_size) == TRUE) {
			unsigned int pcm_len;
			r = 0;	/* success */
			pcm_len = HTS_Engine_get_generated_speech_size(
					&app->engine);
			app->pcm = malloc(pcm_len * sizeof(short));
			HTS_Engine_get_generated_speech(&app->engine, app->pcm);
			play_write(app->play_h, app->pcm,
				   pcm_len * sizeof(short));
		}

		if (app->logfp) {
			fprintf(app->logfp, "[Text analysis result]\n");
			NJD_fprint(&app->njd, app->logfp);
			fprintf(app->logfp, "\n[Output label]\n");
			HTS_Engine_save_label(&app->engine, app->logfp);
			fprintf(app->logfp, "\n");
			HTS_Engine_save_information(&app->engine, app->logfp);
		}
		HTS_Engine_refresh(&app->engine);
	}
	JPCommon_refresh(&app->jpcommon);
	NJD_refresh(&app->njd);
	Mecab_refresh(&app->mecab);

	return r;
}
Exemplo n.º 5
0
static int Open_JTalk_synthesis(Open_JTalk * open_jtalk, const char *txt, FILE * wavfp,
                                FILE * logfp)
{
   int result = 0;
   char buff[MAXBUFLEN];

   text2mecab(buff, txt);
   Mecab_analysis(&open_jtalk->mecab, buff);
   mecab2njd(&open_jtalk->njd, Mecab_get_feature(&open_jtalk->mecab),
             Mecab_get_size(&open_jtalk->mecab));
   njd_set_pronunciation(&open_jtalk->njd);
   njd_set_digit(&open_jtalk->njd);
   njd_set_accent_phrase(&open_jtalk->njd);
   njd_set_accent_type(&open_jtalk->njd);
   njd_set_unvoiced_vowel(&open_jtalk->njd);
   njd_set_long_vowel(&open_jtalk->njd);
   njd2jpcommon(&open_jtalk->jpcommon, &open_jtalk->njd);
   JPCommon_make_label(&open_jtalk->jpcommon);
   if (JPCommon_get_label_size(&open_jtalk->jpcommon) > 2) {
      if (HTS_Engine_synthesize_from_strings
          (&open_jtalk->engine, JPCommon_get_label_feature(&open_jtalk->jpcommon),
           JPCommon_get_label_size(&open_jtalk->jpcommon)) == TRUE)
         result = 1;
      if (wavfp != NULL)
         HTS_Engine_save_riff(&open_jtalk->engine, wavfp);
      if (logfp != NULL) {
         fprintf(logfp, "[Text analysis result]\n");
         NJD_fprint(&open_jtalk->njd, logfp);
         fprintf(logfp, "\n[Output label]\n");
         HTS_Engine_save_label(&open_jtalk->engine, logfp);
         fprintf(logfp, "\n");
         HTS_Engine_save_information(&open_jtalk->engine, logfp);
      }
      HTS_Engine_refresh(&open_jtalk->engine);
   }
   JPCommon_refresh(&open_jtalk->jpcommon);
   NJD_refresh(&open_jtalk->njd);
   Mecab_refresh(&open_jtalk->mecab);

   return result;
}