如何使用 espeak API 枚举可用的语音和语言?
How can I enumerate available voices and languages using espeak API?
我正在使用来自 C++ 的 espeak API 来做一些简单的文本到语音合成嵌入式应用程序。目前,我已经从关于如何开始的基本示例中复制了这一行:
espeak_SetVoiceByName("default");
这似乎工作正常,但我知道 espeak 带有几种不同语言的几种声音。我如何使用 espeak 枚举 那些以及后来 select 他们 API?
使用直接在您使用的函数下方定义的 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
函数,用于根据请求枚举语音,定义在我引用的函数的正上方。
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;
我正在使用来自 C++ 的 espeak API 来做一些简单的文本到语音合成嵌入式应用程序。目前,我已经从关于如何开始的基本示例中复制了这一行:
espeak_SetVoiceByName("default");
这似乎工作正常,但我知道 espeak 带有几种不同语言的几种声音。我如何使用 espeak 枚举 那些以及后来 select 他们 API?
使用直接在您使用的函数下方定义的 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
函数,用于根据请求枚举语音,定义在我引用的函数的正上方。
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;