1

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

espeak_SetVoiceByName("default"); 

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

4

2 回答 2

2

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

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

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;
于 2015-04-01T22:10:15.773 回答
1

使用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函数用于根据请求枚举声音,定义在我引用的函数的正上方。

于 2015-03-28T21:32:58.040 回答