RHEL7.2上已经自带了eSpeak库。
eSpeak是一个小型的、开放源码的语音合成系统,支持多种语言。eSpeak使用共振峰合成方法,这可以使提供的语言文件非常小。该系统支持Windows平台上的SAPI5,所以能用于屏幕阅读程序和其他支持Windows SAPI5接口的程序。eSpeak可以将文本转换成音素代码,因此它也可以用于另一个语音合成引擎的前端。
Mandarin Chinese
This speaks Pinyin text and Chinese characters. There is only a simple one-to-one translation of Chinese characters to a single Pinyin pronunciation. There is no attempt yet at recognising different pronunciations of Chinese characters in context, or of recognising sequences of characters as “words”. The eSpeak installation includes a basic set of Chinese characters. More are available in an additional data file for Mandarin Chinese at: http://espeak.sourceforge.net/data/.
直接上源码:
#include "speak_lib.h" // 包括espeak的头文件
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
// 初始化
espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0);
char word[] = "这是我的工作站, 12345";
// 设置音源为中文女声
espeak_SetVoiceByName("zh+f2");
// 发音
espeak_Synth(word, strlen(word) + 1, 0, POS_CHARACTER, 0, espeakCHARS_UTF8, NULL, NULL);
// 等一段时间,否则程序会立即退出,听不到发音
sleep(4);
char word2[] = "this is my workstation, 12345";
// 设置音源为英文女声
espeak_SetVoiceByName("en+f2");
// 发音
espeak_Synth(word2, strlen(word2) + 1, 0, POS_CHARACTER, 0, espeakCHARS_UTF8, NULL, NULL);
// 等一段时间,否则程序会立即退出,听不到发音
sleep(4);
// 回收资源
espeak_Terminate();
}