c++text-to-speechespeak

How can I enumerate available voices and languages using espeak API?


I am using espeak API from C++ to do some simple text to speech synthesis from my embedded app. Currently, I have copied this line from the basic example on how to get started:

espeak_SetVoiceByName("default"); 

This seems to work fine, however I know that espeak comes with several voices in several different languages. How can I enumerate those and later select them using espeak API?


Solution

  • The documentation for espeak API is the headerfile itself. You can find it here.

    To enumerate existing voices, you can use something like this:

    const espeak_VOICE **list=espeak_ListVoices(0);
    espeak_VOICE *voice=0;
    for(;*list!=0;++list){
        voice=*list;
        if(0!=voice){
            //Look at voice parameters such has voice->name here
        }
    }
    

    Later when you have found a voice you want to use, you can set it with this:

    if(0!=voice){
        espeak_SetVoiceByProperties(voice);
    }
    

    The espeak_VOICE struct is defined like this:

    typedef struct {
        const char *name;      // a given name for this voice. UTF8 string.
        const char *languages;       // list of pairs of (byte) priority + (string) language (and dialect qualifier)
        const char *identifier;      // the filename for this voice within espeak-data/voices
        unsigned char gender;  // 0=none 1=male, 2=female,
        unsigned char age;     // 0=not specified, or age in years
        unsigned char variant; // only used when passed as a parameter to espeak_SetVoiceByProperties
        unsigned char xx1;     // for internal use
        int score;       // for internal use
        void *spare;     // for internal use
    } espeak_VOICE;