如何使用espeak API枚举可用的语音和语言?

时间:2015-03-28 21:21:18

标签: c++ text-to-speech espeak

我正在使用 C ++ 中的espeak API 从我的嵌入式应用中进行一些简单的文本到语音合成。目前,我已从基本示例中复制了关于如何开始的这一行:

espeak_SetVoiceByName("default"); 

这似乎工作正常,但我知道espeak有几种不同语言的声音。我如何枚举那些以及稍后选择使用espeak API?

2 个答案:

答案 0 :(得分:1)

espeak API的文档是头文件本身。你可以找到它here

要枚举现有的声音,您可以使用以下内容:

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
    }
}

稍后当您找到想要使用的语音时,可以使用以下语句进行设置:

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

espeak_VOICE结构的定义如下:

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;

答案 1 :(得分:0)

使用您所使用的espeak_SetVoiceByProperties函数直接定义的函数。

#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
*/

espeak_VOICE结构已定义并记录在其上方不远处。

espeak_ListVoices函数,根据请求枚举语音,定义在我引用的函数的正上方。