提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
使用科大TTS开发包,过程记录
一、TTS
官网注册账号,获取appID,appID和动态库绑定。更换appID就需要更换动态库,但是不用更换语音合成的配置文件。
科大TTS链接
二、使用步骤
1.引入
windows系统(linux系统中头文件不变)
头文件
#include “qtts.h”
#include “msp_errors.h”
#include “msp_cmn.h”
#include “msp_types.h”
动态库 msc.dll和msc_x64.dll,对应32位和64位
linux动态库:libmsc(x86架构)
注意:动态库只和架构有关,其他架构机器需要联系科大交叉编译,官网给了x86的。
2.代码
代码如下(官网demo):改成用接口形式调用
接口参数
text:文本(目前自测支持中英文、数字,但是12会读成一二,不是十二,还不知道怎么改)
filename:文件名称,用来保存音频文件,比如:123.wav
audioFolderPath:音频文件保存的文件夹路径
2.1代码解释
获取当前日期加后缀wav作为音频文件名称
std::string getAudioFilename()
{
//获取音频文本名称
auto now = std::chrono::system_clock::now();
time_t currentTime = std::chrono::system_clock::to_time_t(now);
tm *localTime = localtime(¤tTime);
static char buffer[80];
strftime(buffer, sizeof(buffer), "%Y%m%d%H%M%S", localTime);
std::string filename = std::string(buffer) + ".wav";
return filename;
}
TTS接口实现
int singleTextToSpeech(const std::string& text, std::string &filename, const std::string& audioFolderPath)
{
filename = getAudioFilename();//自写的以当前日期作文音频文件名称
std::string filePath = audioFolderPath + "/" +filename;//绝对路径传入,文件夹路径+文件名
const char* src_text = text.c_str();
const char* des_path = filePath.c_str();
int ret = -1;
FILE* fp = NULL;
const char* sessionID = NULL;
unsigned<