static void DisplayVoices(FILE *f_out, char *language) { int ix; const char *p; int len; int count; int c; size_t j; const espeak_VOICE *v; const char *lang_name; char age_buf[12]; char buf[80]; const espeak_VOICE **voices; espeak_VOICE voice_select; static char genders[4] = { '-', 'M', 'F', '-' }; if ((language != NULL) && (language[0] != 0)) { // display only voices for the specified language, in order of priority voice_select.languages = language; voice_select.age = 0; voice_select.gender = 0; voice_select.name = NULL; voices = espeak_ListVoices(&voice_select); } else voices = espeak_ListVoices(NULL); fprintf(f_out, "Pty Language Age/Gender VoiceName File Other Languages\n"); for (ix = 0; (v = voices[ix]) != NULL; ix++) { count = 0; p = v->languages; while (*p != 0) { len = strlen(p+1); lang_name = p+1; if (v->age == 0) strcpy(age_buf, " --"); else sprintf(age_buf, "%3d", v->age); if (count == 0) { for (j = 0; j < sizeof(buf); j++) { // replace spaces in the name if ((c = v->name[j]) == ' ') c = '_'; if ((buf[j] = c) == 0) break; } fprintf(f_out, "%2d %-15s%s/%c %-18s %-20s ", p[0], lang_name, age_buf, genders[v->gender], buf, v->identifier); } else fprintf(f_out, "(%s %d)", lang_name, p[0]); count++; p += len+2; } fputc('\n', f_out); } }
void PlatformSpeechSynthesisProviderEfl::initializeVoiceList(Vector<RefPtr<PlatformSpeechSynthesisVoice>>& voiceList) { if (!engineInit()) { fireSpeechEvent(SpeechError); return; } espeak_VOICE* espeakVoice = currentVoice(); ASSERT(espeakVoice); String currentLanguage = ASCIILiteral(espeakVoice->languages); const espeak_VOICE** voices = espeak_ListVoices(nullptr); if (!voices) { fireSpeechEvent(SpeechError); return; } // Voices array is terminated by the nullptr for (int i = 0; voices[i]; i++) { const espeak_VOICE* voice = voices[i]; String id = ASCIILiteral(voice->identifier); String name = ASCIILiteral(voice->name); String language = ASCIILiteral(voice->languages); voiceList.append(PlatformSpeechSynthesisVoice::create(id, name, language, true, language == currentLanguage)); } }
eSpeakNGWorker() : rate(espeakRATE_NORMAL), pitch(50), current_voice(NULL) { if (!gSamplerate) { gSamplerate = espeak_Initialize( AUDIO_OUTPUT_SYNCHRONOUS, 100, NULL, espeakINITIALIZE_DONT_EXIT); } samplerate = gSamplerate; voices = espeak_ListVoices(NULL); }
espeak_ERROR SetVoiceByName(const char *name) {//========================================= espeak_VOICE *v; int ix; espeak_VOICE voice_selector; char *variant_name; static char buf[60]; strncpy0(buf,name,sizeof(buf)); variant_name = ExtractVoiceVariantName(buf, 0, 1); for(ix=0; ; ix++) { // convert voice name to lower case (ascii) if((buf[ix] = tolower(buf[ix])) == 0) break; } memset(&voice_selector,0,sizeof(voice_selector)); voice_selector.name = (char *)name; // include variant name in voice stack ?? // first check for a voice with this filename // This may avoid the need to call espeak_ListVoices(). if(LoadVoice(buf,1) != NULL) { if(variant_name[0] != 0) { LoadVoice(variant_name,2); } DoVoiceChange(voice); voice_selector.languages = voice->language_name; SetVoiceStack(&voice_selector, variant_name); return(EE_OK); } if(n_voices_list == 0) espeak_ListVoices(NULL); // create the voices list if((v = SelectVoiceByName(voices_list,buf)) != NULL) { if(LoadVoice(v->identifier,0) != NULL) { if(variant_name[0] != 0) { LoadVoice(variant_name,2); } DoVoiceChange(voice); voice_selector.languages = voice->language_name; SetVoiceStack(&voice_selector, variant_name); return(EE_OK); } } return(EE_INTERNAL_ERROR); // voice name not found } // end of SetVoiceByName
espeak_VOICE *SelectVoiceByName(espeak_VOICE **voices, const char *name) {//===================================================================== int ix; int match_fname = -1; int match_fname2 = -1; int match_name = -1; const char *id; int last_part_len; char last_part[41]; if(voices == NULL) { if(n_voices_list == 0) espeak_ListVoices(NULL); // create the voices list voices = voices_list; } sprintf(last_part,"%c%s",PATHSEP,name); last_part_len = strlen(last_part); for(ix=0; voices[ix] != NULL; ix++) { if(strcmp(name,voices[ix]->name)==0) { match_name = ix; // found matching voice name break; } else if(strcmp(name,id = voices[ix]->identifier)==0) { match_fname = ix; // matching identifier, use this if no matching name } else if(strcmp(last_part,&id[strlen(id)-last_part_len])==0) { match_fname2 = ix; } } if(match_name < 0) { match_name = match_fname; // no matching name, try matching filename if(match_name < 0) match_name = match_fname2; // try matching just the last part of the filename } if(match_name < 0) return(NULL); return(voices[match_name]); } // end of SelectVoiceByName
espeak_VOICE *SelectVoiceByName(espeak_VOICE **voices, const char *name2) { int ix; int match_fname = -1; int match_fname2 = -1; int match_name = -1; const char *id; // this is the filename within espeak-data/voices char *variant_name; int last_part_len; char last_part[41]; char name[40]; if (voices == NULL) { if (n_voices_list == 0) espeak_ListVoices(NULL); // create the voices list voices = voices_list; } strncpy0(name, name2, sizeof(name)); if ((variant_name = strchr(name, '+')) != NULL) { *variant_name = 0; variant_name++; } sprintf(last_part, "%c%s", PATHSEP, name); last_part_len = strlen(last_part); for (ix = 0; voices[ix] != NULL; ix++) { if (strcasecmp(name, voices[ix]->name) == 0) { match_name = ix; // found matching voice name break; } else { id = voices[ix]->identifier; if (strcasecmp(name, id) == 0) match_fname = ix; // matching identifier, use this if no matching name else if (strcasecmp(last_part, &id[strlen(id)-last_part_len]) == 0) match_fname2 = ix; } } if (match_name < 0) { match_name = match_fname; // no matching name, try matching filename if (match_name < 0) match_name = match_fname2; // try matching just the last part of the filename } if (match_name < 0) return NULL; return voices[match_name]; }
static void espeak_info(t_espeak*x){ const espeak_VOICE**voices=espeak_ListVoices(NULL); int i=0; while(voices[i]) { t_atom ap[3]; SETSYMBOL(ap+0, gensym(voices[i]->name)); SETSYMBOL(ap+1, gensym(voices[i]->languages)); SETSYMBOL(ap+2, gensym(voices[i]->identifier)); outlet_anything(x->x_infoout, gensym("voice"), 3, ap); i++; } }
JNIEXPORT jobjectArray JNICALL Java_com_googlecode_eyesfree_espeak_SpeechSynthesis_nativeGetAvailableVoices( JNIEnv *env, jobject object) { if (DEBUG) LOGV("%s", __FUNCTION__); const espeak_VOICE **voices = espeak_ListVoices(NULL); int count; // First, count the number of voices returned. for (count = 0; voices[count] != NULL; count++); // Next, create a Java String array. jobjectArray voicesArray = (jobjectArray) env->NewObjectArray( count * 4, env->FindClass("java/lang/String"), NULL); const espeak_VOICE *v; char gender_buf[12]; char age_buf[12]; // Finally, populate the array. for (int i = 0, voicesIndex = 0; (v = voices[i]) != NULL; i++) { const char *lang_name = v->languages + 1; const char *identifier = v->identifier; sprintf(gender_buf, "%d", v->gender); sprintf(age_buf, "%d", v->age); env->SetObjectArrayElement( voicesArray, voicesIndex++, env->NewStringUTF(lang_name)); env->SetObjectArrayElement( voicesArray, voicesIndex++, env->NewStringUTF(identifier)); env->SetObjectArrayElement( voicesArray, voicesIndex++, env->NewStringUTF(gender_buf)); env->SetObjectArrayElement( voicesArray, voicesIndex++, env->NewStringUTF(age_buf)); } return voicesArray; }
MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style): wxFrame(parent, id, title, pos, size, style) {//=================================================================================================================== // Main Frame constructor int error_flag = 0; int result; int param; int srate; notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxSize(312,760)); // notebook->AddPage(voicedlg,_T("Voice"),FALSE); formantdlg = new FormantDlg(notebook); notebook->AddPage(formantdlg,_T(" Spect"),FALSE); voicedlg = new VoiceDlg(notebook); transldlg = new TranslDlg(notebook); notebook->AddPage(transldlg,_T("Text"),TRUE); screenpages = new wxNotebook(this, ID_SCREENPAGES, wxDefaultPosition, wxSize(554,702)); wxBoxSizer *framesizer = new wxBoxSizer( wxHORIZONTAL ); framesizer->Add( notebook, 0, // make horizontally stretchable wxEXPAND | // make vertically stretchable wxALL, // and make border all around 4 ); // set border width framesizer->Add( screenpages, 1, // make horizontally stretchable wxEXPAND | // make vertically stretchable wxALL, // and make border all around 4 ); // set border width SetSizer( framesizer ); // use the sizer for layout framesizer->SetSizeHints( this ); // set size hints to honour minimum size SetSize(pos.x, pos.y, size.GetWidth(), size.GetHeight()); LoadConfig(); if((result = LoadPhData(&srate)) != 1) { if(result == -1) wxLogError(_T("Failed to read espeak-data/phontab,phondata,phonindex\nPath = ")+wxString(path_home,wxConvLocal)+_T("\n\nThe 'eSpeak' package needs to be installed")); else wxLogError(_T("Wrong version of espeak-data at:\n")+ wxString(path_home,wxConvLocal)+_T("\nVersion 0x%x (expects 0x%x)"),result,version_phdata); error_flag = 1; srate = 22050; } WavegenInit(srate,0); WavegenInitSound(); f_trans = stdout; option_ssml = 1; option_phoneme_input = 1; // if(LoadVoice(voice_name,0) == NULL) if(SetVoiceByName(voice_name2) != EE_OK) { if(error_flag==0) wxLogError(_T("Failed to load voice data")); strcpy(dictionary_name,"en"); } WavegenSetVoice(voice); for(param=0; param<N_SPEECH_PARAM; param++) param_stack[0].parameter[param] = param_defaults[param]; SetParameter(espeakRATE,option_speed,0); SetSpeed(3); SynthesizeInit(); InitSpectrumDisplay(); InitProsodyDisplay(); // InitWaveDisplay(); espeak_ListVoices(NULL); m_timer.SetOwner(this,1); m_timer.Start(500); /* 0.5 timer */ } // end of MyFrame::MyFrame
void DisplayVoices(FILE *f_out, char *language) {//============================================ int ix; const char *p; int len; int count; int scores = 0; const espeak_VOICE *v; const char *lang_name; char age_buf[12]; const espeak_VOICE **voices; espeak_VOICE voice_select; static char genders[4] = {' ','M','F',' '}; if((language != NULL) && (language[0] != 0)) { // display only voices for the specified language, in order of priority voice_select.languages = language; voice_select.age = 0; voice_select.gender = 0; voice_select.name = NULL; voices = espeak_ListVoices(&voice_select); scores = 1; } else { voices = espeak_ListVoices(NULL); } fprintf(f_out,"Pty Language Age/Gender VoiceName File Other Langs\n"); for(ix=0; (v = voices[ix]) != NULL; ix++) { count = 0; p = v->languages; while(*p != 0) { len = strlen(p+1); lang_name = p+1; if(v->age == 0) strcpy(age_buf," "); else sprintf(age_buf,"%3d",v->age); if(count==0) { fprintf(f_out,"%2d %-12s%s%c %-17s %-11s ", p[0],lang_name,age_buf,genders[v->gender],v->name,v->identifier); } else { fprintf(f_out,"(%s %d)",lang_name,p[0]); } count++; p += len+2; } // if(scores) // fprintf(f_out,"%3d ",v->score); fputc('\n',f_out); } } // end of DisplayVoices
char const *SelectVoice(espeak_VOICE *voice_select, int *found) {//============================================================ // Returns a path within espeak-voices, with a possible +variant suffix // variant is an output-only parameter int nv; // number of candidates int ix, ix2; int j; int n_variants; int variant_number; int gender; int skip; int aged=1; char *variant_name; const char *p, *p_start; espeak_VOICE *vp = NULL; espeak_VOICE *vp2; espeak_VOICE voice_select2; espeak_VOICE *voices[N_VOICES_LIST]; // list of candidates espeak_VOICE *voices2[N_VOICES_LIST+N_VOICE_VARIANTS]; static espeak_VOICE voice_variants[N_VOICE_VARIANTS]; static char voice_id[50]; *found = 1; memcpy(&voice_select2,voice_select,sizeof(voice_select2)); if(n_voices_list == 0) espeak_ListVoices(NULL); // create the voices list if((voice_select2.languages == NULL) || (voice_select2.languages[0] == 0)) { // no language is specified. Get language from the named voice static char buf[60]; if(voice_select2.name == NULL) { if((voice_select2.name = voice_select2.identifier) == NULL) voice_select2.name = "default"; } strncpy0(buf,voice_select2.name,sizeof(buf)); variant_name = ExtractVoiceVariantName(buf,0,0); vp = SelectVoiceByName(voices_list,buf); if(vp != NULL) { voice_select2.languages = &(vp->languages[1]); if((voice_select2.gender==0) && (voice_select2.age==0) && (voice_select2.variant==0)) { if(variant_name[0] != 0) { sprintf(voice_id,"%s+%s", vp->identifier, variant_name); return(voice_id); } return(vp->identifier); } } } // select and sort voices for the required language nv = SetVoiceScores(&voice_select2,voices,0); if(nv == 0) { // no matching voice, choose the default *found = 0; if((voices[0] = SelectVoiceByName(voices_list,"default")) != NULL) nv = 1; } gender = 0; if((voice_select2.gender == 2) || ((voice_select2.age > 0) && (voice_select2.age < 13))) gender = 2; else if(voice_select2.gender == 1) gender = 1; #define AGE_OLD 60 if(voice_select2.age < AGE_OLD) aged = 0; p = p_start = variant_lists[gender]; if(aged == 0) p++; // the first voice in the variants list is older // add variants for the top voices n_variants = 0; for(ix=0, ix2=0; ix<nv; ix++) { vp = voices[ix]; // is the main voice the required gender? skip=0; if((gender != 0) && (vp->gender != gender)) { skip=1; } if((ix2==0) && aged && (vp->age < AGE_OLD)) { skip=1; } if(skip==0) { voices2[ix2++] = vp; } for(j=0; (j < vp->xx1) && (n_variants < N_VOICE_VARIANTS);) { if((variant_number = *p) == 0) { p = p_start; continue; } vp2 = &voice_variants[n_variants++]; // allocate space for voice variant memcpy(vp2,vp,sizeof(espeak_VOICE)); // copy from the original voice vp2->variant = variant_number; voices2[ix2++] = vp2; p++; j++; } } // add any more variants to the end of the list while((vp != NULL) && ((variant_number = *p++) != 0) && (n_variants < N_VOICE_VARIANTS)) { vp2 = &voice_variants[n_variants++]; // allocate space for voice variant memcpy(vp2,vp,sizeof(espeak_VOICE)); // copy from the original voice vp2->variant = variant_number; voices2[ix2++] = vp2; } // index the sorted list by the required variant number if(ix2 == 0) return(NULL); vp = voices2[voice_select2.variant % ix2]; if(vp->variant != 0) { variant_name = ExtractVoiceVariantName(NULL, vp->variant, 0); sprintf(voice_id,"%s+%s", vp->identifier, variant_name); return(voice_id); } return(vp->identifier); } // end of SelectVoice