diff --git a/Makefile.am b/Makefile.am index 8aabbf12..f4ca4afa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -58,6 +58,7 @@ libespeak_ng_include_HEADERS = \ common_FLAGS = -Isrc/include/espeak-ng common_SOURCE = \ + src/libespeak-ng/compiledata.c \ src/libespeak-ng/compiledict.c \ src/libespeak-ng/dictionary.c \ src/libespeak-ng/intonation.c \ diff --git a/src/compiledata.cpp b/src/compiledata.cpp index 58fbbe8e..adaabcc0 100644 --- a/src/compiledata.cpp +++ b/src/compiledata.cpp @@ -3718,104 +3718,6 @@ fprintf(f_errors,"\nRefs %d, Reused %d\n",count_references,duplicate_references ReadPhondataManifest(); } // end of CompilePhonemeData -#include - -void CompileMbrola(const wxChar *mbrola_file) -{//================= - char *p; - FILE *f_in; - FILE *f_out; - int percent; - int n; - int *pw; - int *pw_end; - int count = 0; - int control; - char phoneme[40]; - char phoneme2[40]; - char name1[40]; - char name2[40]; - char mbrola_voice[40]; - char buf[sizeof(path_home)+30]; - int mbrola_ctrl = 20; // volume in 1/16 ths - MBROLA_TAB data[N_PHONEME_TAB]; - - wxString filepath; - if (mbrola_file == NULL) - { - filepath = wxFileSelector(_T("Read Mbrola phonemes file"),path_phsource+_T("/mbrola"),_T(""),_T(""),_T("*"),wxOPEN); - } - else - { - filepath = mbrola_file; - } - strcpy(buf,filepath.mb_str(wxConvLocal)); - if((f_in = fopen(buf,"r")) == NULL) - { - wxLogError(_T("Can't read: ")+filepath); - return; - } - - while(fgets(buf,sizeof(phoneme),f_in) != NULL) - { - buf[sizeof(phoneme)-1] = 0; - - if((p = strstr(buf,"//")) != NULL) - *p = 0; // truncate line at comment - - if(memcmp(buf,"volume",6)==0) - { - mbrola_ctrl = atoi(&buf[6]); - continue; - } - - n = sscanf(buf,"%d %s %s %d %s %s",&control,phoneme,phoneme2,&percent,name1,name2); - if(n >= 5) - { - data[count].name = StringToWord(phoneme); - if(strcmp(phoneme2,"NULL")==0) - data[count].next_phoneme = 0; - else - if(strcmp(phoneme2,"VWL")==0) - data[count].next_phoneme = 2; - else - data[count].next_phoneme = StringToWord(phoneme2); - data[count].mbr_name = 0; - data[count].mbr_name2 = 0; - data[count].percent = percent; - data[count].control = control; - if(strcmp(name1,"NULL")!=0) - data[count].mbr_name = StringToWord(name1); - if(n == 6) - data[count].mbr_name2 = StringToWord(name2); - - count++; - } - } - fclose(f_in); - - wxFileName filename = wxFileName(filepath); - strcpy(mbrola_voice,filename.GetName().mb_str(wxConvLocal)); - sprintf(buf,"%s/mbrola_ph/%s_phtrans",path_home,mbrola_voice); - if((f_out = fopen(buf,"wb")) == NULL) - { - wxLogError(_T("Can't write to: ")+wxString(buf,wxConvLocal)); - return; - } - - data[count].name = 0; // list terminator - Write4Bytes(f_out, mbrola_ctrl); - - pw_end = (int *)(&data[count+1]); - for(pw = (int *)data; pw < pw_end; pw++) - { - Write4Bytes(f_out, *pw); - } - fclose(f_out); - wxLogStatus(_T("Mbrola translation file: %d phonemes"),count); -} // end of CompileMbrola - - static const char *preset_tune_names[] = { "s1", "c1", "q1", "e1", NULL}; diff --git a/src/espeakedit.cpp b/src/espeakedit.cpp index 4fe48840..6b937fbf 100644 --- a/src/espeakedit.cpp +++ b/src/espeakedit.cpp @@ -63,7 +63,7 @@ extern void DictionarySort(const char *dictname); extern void init_z(); extern void CompilePhonemeData(void); extern void CompileSampleRate(void); -extern void CompileMbrola(const wxChar *mbrola_file = NULL); +extern "C" void CompileMbrola(const char *mbrola_file); extern void CompileIntonation(); extern void InitSpectrumDisplay(); extern void InitProsodyDisplay(); @@ -790,7 +790,10 @@ void MyFrame::OnTools(wxCommandEvent& event) break; case MENU_COMPILE_MBROLA: - CompileMbrola(); + { + wxString filepath = wxFileSelector(_T("Read Mbrola phonemes file"),path_phsource+_T("/mbrola"),_T(""),_T(""),_T("*"),wxOPEN); + CompileMbrola(filepath.mb_str(wxConvLocal)); + } break; case MENU_COMPILE_INTONATION: diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c new file mode 100644 index 00000000..a85a75ee --- /dev/null +++ b/src/libespeak-ng/compiledata.c @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (C) 2005 to 2014 by Jonathan Duddington * + * email: jonsd@users.sourceforge.net * + * Copyright (C) 2013-2015 Reece H. Dunn * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see: * + * . * + ***************************************************************************/ + +#include +#include + +#include "speak_lib.h" + +#include "phoneme.h" +#include "speech.h" +#include "synthesize.h" + +static unsigned int StringToWord(const char *string) +{ + // Pack 4 characters into a word + int ix; + unsigned char c; + unsigned int word; + + if(string==NULL) + return(0); + + word = 0; + for(ix=0; ix<4; ix++) + { + if(string[ix]==0) break; + c = string[ix]; + word |= (c << (ix*8)); + } + return(word); +} + +void CompileMbrola(const char *filepath) +{ + char *p; + FILE *f_in; + FILE *f_out; + int percent; + int n; + int *pw; + int *pw_end; + int count = 0; + int control; + char phoneme[40]; + char phoneme2[40]; + char name1[40]; + char name2[40]; + char mbrola_voice[40]; + char buf[sizeof(path_home)+30]; + int mbrola_ctrl = 20; // volume in 1/16 ths + MBROLA_TAB data[N_PHONEME_TAB]; + + strcpy(buf,filepath); + if((f_in = fopen(buf,"r")) == NULL) + { + fprintf(stderr, "Can't read: %s\n", filepath); + return; + } + + while(fgets(buf,sizeof(phoneme),f_in) != NULL) + { + buf[sizeof(phoneme)-1] = 0; + + if((p = strstr(buf,"//")) != NULL) + *p = 0; // truncate line at comment + + if(memcmp(buf,"volume",6)==0) + { + mbrola_ctrl = atoi(&buf[6]); + continue; + } + + n = sscanf(buf,"%d %s %s %d %s %s",&control,phoneme,phoneme2,&percent,name1,name2); + if(n >= 5) + { + data[count].name = StringToWord(phoneme); + if(strcmp(phoneme2,"NULL")==0) + data[count].next_phoneme = 0; + else + if(strcmp(phoneme2,"VWL")==0) + data[count].next_phoneme = 2; + else + data[count].next_phoneme = StringToWord(phoneme2); + data[count].mbr_name = 0; + data[count].mbr_name2 = 0; + data[count].percent = percent; + data[count].control = control; + if(strcmp(name1,"NULL")!=0) + data[count].mbr_name = StringToWord(name1); + if(n == 6) + data[count].mbr_name2 = StringToWord(name2); + + count++; + } + } + fclose(f_in); + + strcpy(mbrola_voice,basename(filepath)); + sprintf(buf,"%s/mbrola_ph/%s_phtrans",path_home,mbrola_voice); + if((f_out = fopen(buf,"wb")) == NULL) + { + fprintf(stderr, "Can't write to: %s\n", buf); + return; + } + + data[count].name = 0; // list terminator + Write4Bytes(f_out, mbrola_ctrl); + + pw_end = (int *)(&data[count+1]); + for(pw = (int *)data; pw < pw_end; pw++) + { + Write4Bytes(f_out, *pw); + } + fclose(f_out); + fprintf(stdout, "Mbrola translation file: %d phonemes", count); +}