void setText( char *rel, char *val ) { strcpy( slot_Speak_stat, "PROCESSING" ); if( prop_Speak_stat == AutoOutput ) inqSpeakStat(); if( strcmp(rel,"=")==0 ) { refresh(); text_analysis( val ); /* テキスト解析 */ if( prop_Text_text == AutoOutput ) inqTextText(); if( prop_Speak_text == AutoOutput ) inqSpeakText(); parameter_generation(); /* パラメータ生成(F0,MLSAフィルタ係数,継続長) */ do_synthesis(); /* 合成波形の生成 */ #ifdef PRINTDATA TmpMsg( "Synthesis Done.\n" ); #endif /* } else if( strcmp(rel,"<")==0 ) { } else if( strcmp(rel,"<<")==0 ) { */ } else { unknown_com(); } strcpy( slot_Speak_stat, "READY" ); if( prop_Speak_stat == AutoOutput ) inqSpeakStat(); }
static int socket_accept(GSOCKET sock) { int len; int child_fd; if (FD_ISSET(sock->fd, &sock->readfds) != 0) { len = sizeof(sock->addr); if ((child_fd = accept(sock->fd, (struct sockaddr *)&sock->addr, &len)) == -1) { return -1; } if (sock->child_fd == -1) { sock->child_fd = child_fd; } else { TmpMsg("Refuse connection.\n"); #if defined(_WIN32) && !defined(__CYGWIN32__) closesocket(child_fd); #else close(child_fd); #endif } } return 1; }
/* 茶筌の結果をファイルから読み込み */ void setParsedText( char *rel, char *filename ) { if( strcmp(rel,"=")==0 ) { refresh(); text_analysis_file( filename ); /* テキスト解析 */ parameter_generation(); /* パラメータ生成(F0,MLSAフィルタ係数,継続長) */ do_synthesis(); /* 合成波形の生成 */ #ifdef PRINTDATA TmpMsg( "Synthesis Done.\n" ); #endif } else { unknown_com(); } }
void setSpeak( char *rel, char *val ) { int error; long sleep_ms; if( strcmp(rel,"=")!=0 ) { unknown_com(); return; } if( strcmp(val,"NOW")==0 ) { strcpy( slot_Speak_stat, "SPEAKING" ); if( prop_Speak_stat == AutoOutput ) inqSpeakStat(); do_output(NULL); /* 音声出力 */ } else if( strcmp(val,"STOP")==0 ) { abort_output(); } else { /* val = "12:34:56.789" or "+1000" */ error = make_sleep_time( val, &sleep_ms ); if( error ) { unknown_com(); } else { #ifdef PRINTDATA TmpMsg( "sleep_ms: %d\n", sleep_ms ); #endif if( sleep_ms > 0 ) { #ifdef WIN32 Sleep( sleep_ms ); #else usleep( 1000*sleep_ms ); #endif } strcpy( slot_Speak_stat, "SPEAKING" ); if( prop_Speak_stat == AutoOutput ) inqSpeakStat(); do_output(NULL); /* 音声出力 */ } } /* strcpy( slot_Speak_stat, "IDLE" ); if( prop_Speak_stat == AutoOutput ) inqSpeakStat(); */ }
int make_chasen_process( CHASEN_FD *fd_in, CHASEN_FD *fd_out ) { int to_parent[2]; if( chasen_process != 0 ) return 0; pchain[0].command[0] = chasen_bin; pchain[0].command[1] = chasen_rc_option; pchain[0].command[2] = chasen_rc; pchain[0].command[3] = '\0'; if( chaone_bin[0] == '\0' ) { pchain[0].last = 1; /* set 1 if this process is the last */ } else { pchain[0].last = 0; set_command( chaone_bin, pchain[1].command ); pchain[1].last = 1; } /* to_parent は「最後の子 -> 親」で使う。*/ if( pipe(to_parent) < 0 ) { ErrMsg( "pipe error in init_text_analysis\n" ); return -1; } /* 親が書き込むfdはこのルーチンの中で決まる。*/ *fd_out = make_pipe_child( pchain, to_parent ); if( *fd_out < 0 ) return -1; *fd_in = to_parent[0]; /* 親はここから読み出す。*/ close( to_parent[1] ); /* 親はここへは書かない。*/ chasen_process = 1; #ifdef PRINTDATA TmpMsg( "* chasen start.\n" ); #endif return 0; }
int main( int argc, char **argv ) { int n, i; char *com; fp_err = stderr; init_conf(); com = argv[0]; --argc; ++argv; while( argc > 0 && argv[0][0] == '-' ) { switch( argv[0][1] ) { case 'C': if( argc < 2 ) usage( com ); read_conf( argv[1] ); --argc; ++argv; break; /*******↓for server mode *******/ case 'p': /* 引数が不正な場合はエラー出力 */ if( argc < 2 ) usage( com ); /* ポート番号の読み込み */ i = atoi( argv[1] ); if (i > 1024) { nPort = i; } s_mode = 1; --argc; ++argv; break; /*******↑***********************/ case 'v': printf( "%s\n", moduleVersion ); printf( "%s\n", protocolVersion ); exit(0); default: usage( com ); } --argc; ++argv; } set_default_conf(); initialize(); n = setjmp( ebuf ); if( n > 0 ) chasen_process = 0; /* to restart 'chasen' process */ for( ;; ) { #ifdef PRINTDATA TmpMsg( "> " ); #endif n_arg = read_command( v_arg ); #ifdef PRINTDATA { int i; TmpMsg( "command is \n" ); for( i=0; i<n_arg; ++i ) { TmpMsg( " %d: %s\n", i+1, v_arg[i] ); } } #endif /* 「o」 で set Speak = NOW のショートカット */ if( strcmp(v_arg[0],"o")==0 ) { setSpeak( "=", "NOW" ); continue; } if( n_arg < 2 ) { unknown_com(); continue; } switch( commandID( v_arg[0] ) ) { case C_set: if( n_arg < 4 ) { unknown_com(); break; } switch( slotID( v_arg[1] ) ) { case S_Run: setRun( v_arg[2], v_arg[3] ); break; case S_Speaker: setSpeaker( v_arg[2], v_arg[3] ); break; case S_Alpha: setAlpha( v_arg[2], v_arg[3] ); break; case S_Postfilter_coef: setPostfilter_coef( v_arg[2], v_arg[3] ); break; case S_Text: setText( v_arg[2], v_arg[3] ); break; case S_Speak: setSpeak( v_arg[2], v_arg[3] ); break; case S_SaveRAW: setSave( v_arg[2], v_arg[3] ); break; case S_Save: setSave( v_arg[2], v_arg[3] ); break; case S_LoadRAW: setSpeechFile( v_arg[2], v_arg[3], RAW ); break; case S_SpeechFile: setSpeechFile( v_arg[2], v_arg[3], RAW ); break; case S_SaveWAV: setSaveWAV( v_arg[2], v_arg[3] ); break; case S_LoadWAV: setSpeechFile( v_arg[2], v_arg[3], WAV ); break; case S_SavePros: setSavePros( v_arg[2], v_arg[3] ); break; case S_LoadPros: setProsFile( v_arg[2], v_arg[3] ); break; case S_ProsFile: setProsFile( v_arg[2], v_arg[3] ); break; case S_ParsedText: setParsedText( v_arg[2], v_arg[3] ); break; case S_Speak_syncinterval: setSpeakSyncinterval( v_arg[2], v_arg[3] ); break; case S_AutoPlay: slot_Auto_play = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_AutoPlayDelay: slot_Auto_play_delay = atoi( v_arg[3] ); break; case S_Log: setLog( v_arg[2], v_arg[3] ); break; case S_Log_conf: slot_Log_conf = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_text: slot_Log_text = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_arranged_text: slot_Log_arranged_text = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_chasen: slot_Log_chasen = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_tag: slot_Log_tag = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_phoneme: slot_Log_phoneme = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_mora: slot_Log_mora = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_morph: slot_Log_morph = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_aphrase: slot_Log_aphrase = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_breath: slot_Log_breath = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Log_sentence: slot_Log_sentence = setLogYesNo( v_arg[2], v_arg[3] ); break; case S_Err: setErr( v_arg[2], v_arg[3] ); break; default: unknown_com(); } break; case C_inq: switch( slotID( v_arg[1] ) ) { case S_Run: inqRun(); break; case S_ModuleVersion: inqModuleVersion(); break; case S_ProtocolVersion: inqProtocolVersion(); break; case S_SpeakerSet: inqSpeakerSet(); break; case S_Speaker: inqSpeaker(); break; case S_SpeechFile: inqSpeechFile(); break; case S_ProsFile: inqProsFile(); break; case S_AutoPlay: inqAutoPlay(); break; case S_AutoPlayDelay: inqAutoPlayDelay(); break; case S_Text_text: inqTextText(); break; case S_Text_pho: inqTextPho(); break; case S_Text_dur: inqTextDur(); break; case S_Speak_text: inqSpeakText(); break; case S_Speak_pho: inqSpeakPho(); break; case S_Speak_dur: inqSpeakDur(); break; case S_Speak_utt: inqSpeakUtt(); break; case S_Speak_len: inqSpeakLen(); break; case S_Speak_stat: inqSpeakStat(); break; case S_Speak_syncinterval: inqSpeakSyncinterval(); break; case S_Log: RepMsg( "rep Log = %s\n", slot_Log_file ); break; case S_Log_conf: RepMsg( "rep Log.conf = %s\n", YesNoSlot(S_Log_conf) ); break; case S_Log_text: RepMsg( "rep Log.text = %s\n", YesNoSlot(S_Log_text) ); break; case S_Log_arranged_text: RepMsg( "rep Log.arranged_text = %s\n", YesNoSlot(S_Log_arranged_text) ); break; case S_Log_chasen: RepMsg( "rep Log.chasen = %s\n", YesNoSlot(S_Log_chasen) ); break; case S_Log_tag: RepMsg( "rep Log.tag = %s\n", YesNoSlot(S_Log_tag) ); break; case S_Log_phoneme: RepMsg( "rep Log.phoneme = %s\n", YesNoSlot(S_Log_phoneme) ); break; case S_Log_mora: RepMsg( "rep Log.mora = %s\n", YesNoSlot(S_Log_mora) ); break; case S_Log_morph: RepMsg( "rep Log.morph = %s\n", YesNoSlot(S_Log_morph) ); break; case S_Log_aphrase: RepMsg( "rep Log.aphrase = %s\n", YesNoSlot(S_Log_aphrase) ); break; case S_Log_breath: RepMsg( "rep Log.breath = %s\n", YesNoSlot(S_Log_breath) ); break; case S_Log_sentence: RepMsg( "rep Log.sentence = %s\n", YesNoSlot(S_Log_sentence) ); break; case S_Err: RepMsg( "rep Err = %s\n", slot_Err_file ); break; default: unknown_com(); } break; case C_prop: { SlotProp prop; if( strcmp(v_arg[2],"=")!=0 ) { unknown_com(); break; } if( strcmp(v_arg[3],"AutoOutput")==0 ) { prop = AutoOutput; } else if(strcmp(v_arg[3],"NoAutoOutput")==0 ) { prop = NoAutoOutput; } else { unknown_com(); break; } switch( slotID( v_arg[1] ) ) { case S_Run: prop_Run = prop; break; case S_ModuleVersion: prop_ModuleVersion = prop; break; case S_ProtocolVersion: prop_ProtocolVersion = prop; break; case S_SpeakerSet: prop_SpeakerSet = prop; break; case S_Speaker: prop_Speaker = prop; break; case S_SpeechFile: prop_SpeechFile = prop; break; case S_ProsFile: prop_ProsFile = prop; break; case S_Text: prop_Text = prop; break; case S_Text_text: prop_Text_text = prop; break; case S_Text_pho: prop_Text_pho = prop; break; case S_Text_dur: prop_Text_dur = prop; break; case S_Speak: prop_Speak = prop; break; case S_Speak_text: prop_Speak_text = prop; break; case S_Speak_pho: prop_Speak_pho = prop; break; case S_Speak_dur: prop_Speak_dur = prop; break; case S_Speak_utt: prop_Speak_utt = prop; break; case S_Speak_len: prop_Speak_len = prop; break; case S_Speak_stat: prop_Speak_stat = prop; break; case S_Speak_syncinterval: prop_Speak_syncinterval = prop; break; default: unknown_com(); } } break; default: unknown_com(); } } if( s_mode ) { server_destroy (); } exit(0); }
void make_parameter() { Model *m; Tree *t; int state, nframe, i, sid; m = mhead; nframe = 0; for (;;) { /* search pdfs */ state = 2; sid = m->phoneme->sid; if ((m->pitchpdf = (char **) calloc (nstate, sizeof (char *))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((m->pitchmean = (float **) calloc (nstate, sizeof (float *))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((m->pitchvariance = (float **) calloc (nstate, sizeof (float *))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((m->voiced = (Boolean *) calloc (nstate, sizeof (Boolean))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } m->pitchpdf -= 2; m->pitchmean -= 2; m->pitchvariance -= 2; m->voiced -= 2; for (t = mset[sid].thead[PITCH]; t != mset[sid].ttail[PITCH]; t = t->next) { m->pitchpdf[state] = strdup (TraverseTree (m->name, t->parent)); SearchPitchPDF (m, state, sid); state++; } state = 2; if ((m->mceppdf = (char **) calloc (nstate, sizeof (char *))) == NULL ) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((m->mcepmean = (float **) calloc (nstate, sizeof (float *))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((m->mcepvariance = (float **) calloc (nstate, sizeof (float *))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } m->mceppdf -= 2; m->mcepmean -= 2; m->mcepvariance -= 2; for (t = mset[sid].thead[MCEP]; t != mset[sid].ttail[MCEP]; t = t -> next) { m->mceppdf[state] = strdup (TraverseTree (m->name, t->parent)); SearchMcepPDF (m, state, sid); state++; } #ifdef DEBUG TmpMsg("%d %d %s\n", nframe, nframe + m->totalduration, m->name); #endif nframe += m->totalduration; if (m == mtail) break; m = m->next; } /* parameter generation */ totalframe = nframe; f0.rate = FRAME_RATE; if ((f0.data = (double *) calloc (totalframe + 1, sizeof (double))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } power.rate = FRAME_RATE; if ((power.data = (double *) calloc (totalframe + 1, sizeof (double))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } alpha.rate = FRAME_RATE; if ((alpha.data = (double *) calloc (totalframe + 1, sizeof (double))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((mcep = (double **) calloc (totalframe + 1, sizeof (double *))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((coeff = (double **) calloc (totalframe + 1, sizeof (double *))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((voiced = (Boolean *) calloc (totalframe +1, sizeof (Boolean))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } for (i=0; i <= totalframe; i++) { if ((mcep[i] = (double *) calloc (mceppst.order + 1, sizeof (double))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } if ((coeff[i] = (double *) calloc (mceppst.order + 1, sizeof (double))) == NULL) { ErrMsg("Memory allocation error ! (in make_parameter)\n"); restart(1); } } GenerateParam(stdout); /* for (i=0; i <= totalframe; i++) f0.data[i] = (f0.data[i] == 0.0)? 0:f0.data[i]+log(2.0); */ }