void MyFrame::OnTools(wxCommandEvent& event) {//========================================= int err; FILE *log; int debug_flag=0; char fname_log[sizeof(path_dsource)+12]; char err_fname[sizeof(path_home)+15]; switch(event.GetId()) { case MENU_TEST: TestTest(0); break; case MENU_TEST2: TestTest(2); break; case MENU_TO_UTF8: ConvertToUtf8(); break; case MENU_COUNT_WORDS: MakeWordFreqList(); break; case MENU_LEXICON_RU: case MENU_LEXICON_BG: case MENU_LEXICON_DE: case MENU_LEXICON_IT: case MENU_LEXICON_TEST: CompareLexicon(event.GetId()); // Compare a lexicon with _rules translation break; case MENU_COMPILE_PH: CompilePhonemeData(); SetVoiceTitle(voice_name2); break; case MENU_COMPILE_PH2: CompileSampleRate(); SetVoiceTitle(voice_name2); break; case MENU_COMPILE_MBROLA: CompileMbrola(); break; case MENU_COMPILE_INTONATION: CompileIntonation(); break; case MENU_COMPILE_DICT_DEBUG: debug_flag =1; // and drop through to next case case MENU_COMPILE_DICT: sprintf(fname_log,"%s%s",path_dsource,"dict_log"); log = fopen(fname_log,"w"); LoadDictionary(translator, translator->dictionary_name, 0); if((err = CompileDictionary(path_dsource,translator->dictionary_name,log,err_fname,debug_flag)) < 0) { wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal)); wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource); if(!dir.IsEmpty()) { path_dictsource = dir; strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1); strcat(path_dsource,"/"); } break; } wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err); if(log != NULL) { fclose(log); if(err > 0) { // display the error messages DisplayErrorFile(fname_log); } } break; case MENU_FORMAT_DICTIONARY: DictionaryFormat(dictionary_name); break; case MENU_SORT_DICTIONARY: DictionarySort(dictionary_name); break; case MENU_VOWELCHART1: MakeVowelLists(); break; case MENU_VOWELCHART2: VowelChart(2,NULL); break; case MENU_VOWELCHART3: VowelChart(3,NULL); break; case MENU_LOAD_WAV: // LoadWavFile(); break; } }
void MakeVowelLists(void) {//====================== // For each phoneme table, make a list of its vowels and their // formant frequencies (f1,f2,f3) for use by VowelChart() int table; int ix; int phcode; PHONEME_TAB *ph; FILE *f; FILE *f_prog_log; SPECT_SEQ *seq; SPECT_SEQK *seqk; frame_t *frame; int n_prog_log; int vowelfmt_ix; int colour; int voice_found; PHONEME_PROG_LOG *prog_log_table; PHONEME_PROG_LOG *found_prog; PHONEME_PROG_LOG this_prog; char dirname[sizeof(path_source)+20]; char fname[sizeof(dirname)+40]; char save_voice_name[80]; strcpy(save_voice_name,voice_name2); sprintf(fname,"%s%s",path_source,"compile_prog_log"); if((f_prog_log = fopen(fname,"rb")) == NULL) { wxLogError(_T("Can't read 'compile_prog_log;")); return; } ix = GetFileLength(fname); prog_log_table = (PHONEME_PROG_LOG *)malloc(ix); if(prog_log_table == NULL) { fclose(f_prog_log); return; } ix = fread(prog_log_table, 1, ix, f_prog_log); fclose(f_prog_log); n_prog_log = ix / sizeof(PHONEME_PROG_LOG); progress = new wxProgressDialog(_T("Vowel charts"),_T(""),n_phoneme_tables); sprintf(dirname,"%s%s",path_source,"vowelcharts"); mkdir(dirname,S_IRWXU | S_IRGRP | S_IROTH); sprintf(fname,"%s/vowel_log",dirname); for(table=0; table<n_phoneme_tables; table++) { sprintf(fname,"%s/%s",dirname,phoneme_tab_list[table].name); if((f = fopen(fname,"w"))==NULL) continue; progress->Update(table); // select the phoneme table by name // if(SetVoiceByName(phoneme_tab_list[table].name) != 0) continue; if(SelectPhonemeTableName(phoneme_tab_list[table].name) < 0) { fclose(f); continue; } voice_found = 0; if((LoadVoice(phoneme_tab_list[table].name, 0) != NULL) && (translator->data_dictrules != NULL)) { voice_found = 1; FindPhonemesUsed(); } // phoneme table is terminated by a phoneme with no name (=0) for(phcode=1; phcode < n_phoneme_tab; phcode++) { ph = phoneme_tab[phcode]; if((ph==NULL) || (ph->type != phVOWEL) || (ph->program == 0)) continue; if(voice_found && (phoneme_tab_flags[phcode] & 3) == 0) { continue; // inherited, and not used } // find the size of this program this_prog.addr = ph->program; found_prog = (PHONEME_PROG_LOG *)bsearch((void *)&this_prog, (void *)prog_log_table, n_prog_log, sizeof(PHONEME_PROG_LOG), (int(*)(const void *,const void *))prog_log_sorter); FindVowelFmt(ph->program, found_prog->length); for(vowelfmt_ix=0; vowelfmt_ix < n_vowelfmt_addr; vowelfmt_ix++) { ix = vowelfmt_addr[vowelfmt_ix]; seq = (SPECT_SEQ *)(&phondata_ptr[ix]); seqk = (SPECT_SEQK *)seq; if(seq->frame[0].frflags & FRFLAG_KLATT) frame = &seqk->frame[1]; else frame = (frame_t *)&seq->frame[1]; if((n_vowelfmt_addr - vowelfmt_ix) == 1) colour = 0; else colour = 1; fprintf(f,"%s\t %d %3d %4d %4d",WordToString(ph->mnemonic), colour, frame->ffreq[1],frame->ffreq[2],frame->ffreq[3]); if(seq->frame[0].frflags & FRFLAG_KLATT) frame = &seqk->frame[seqk->n_frames-1]; else frame = (frame_t *)&seq->frame[seq->n_frames-1]; fprintf(f," %3d %4d %4d\n",frame->ffreq[1],frame->ffreq[2],frame->ffreq[3]); } } fclose(f); VowelChart(1,fname); // draw the vowel chart } free(prog_log_table); LoadVoice(voice_name2,0); // reset the original phoneme table delete progress; LoadVoiceVariant(save_voice_name,0); }