Reputation: 9698
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?
Upvotes: 2
Views: 743
Reputation: 60
If you have installed the package you might launch espeak directly from the command line, and in this case
espeak --voices
will enumerate all available voices. Just an excerpt from my machine:
Pty Language Age/Gender VoiceName File Other Languages
5 af M afrikaans other/af
5 an M aragonese europe/an
5 bg - bulgarian europe/bg
5 bs M bosnian europe/bs
5 ca M catalan europe/ca
5 cs M czech europe/cs
I've found out that both VoiceName and Language can be used in the espeak_SetVoiceByName API
Upvotes: 1
Reputation: 9698
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;
Upvotes: 2
Reputation: 385405
Use the espeak_SetVoiceByProperties
function that's defined directly below the one you used.
#ifdef __cplusplus
extern "C"
#endif
ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name);
/* Searches for a voice with a matching "name" field. Language is not considered.
"name" is a UTF8 string.
Return: EE_OK: operation achieved
EE_BUFFER_FULL: the command can not be buffered;
you may try after a while to call the function again.
EE_INTERNAL_ERROR.
*/
#ifdef __cplusplus
extern "C"
#endif
ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_spec);
/* An espeak_VOICE structure is used to pass criteria to select a voice. Any of the following
fields may be set:
name NULL, or a voice name
languages NULL, or a single language string (with optional dialect), eg. "en-uk", or "en"
gender 0=not specified, 1=male, 2=female
age 0=not specified, or an age in years
variant After a list of candidates is produced, scored and sorted, "variant" is used to index
that list and choose a voice.
variant=0 takes the top voice (i.e. best match). variant=1 takes the next voice, etc
*/
The espeak_VOICE
structure is defined and documented not far above it.
The espeak_ListVoices
function, to enumerate voices as requested, is defined right above the functions I quoted.
Upvotes: 1