工控编程吧
标题:
TTS语音开发包开发手册开发实例
[打印本页]
作者:
qq263946146
时间:
2017-10-23 15:01
标题:
TTS语音开发包开发手册开发实例
(, 下载次数: 3)
上传
点击文件名下载附件
TTS语音开发包开发手册开发实例
附件有库函数的说明
sapi.chm
库程序
SpeechSDK51.exe
语言包
SpeechSDK51LangPack.exe
WIN7上不能使用,还有提供
win7 TTS补丁.exe
最后是一个简单的实例
123
初始化库
void CMy123Dlg::InitVoice()
{
m_pISpVoice = NULL;
m_pIEnumSpObjectTokens = NULL;
if(S_OK != SpEnumTokens(SPCAT_VOICES, NULL, NULL, &m_pIEnumSpObjectTokens) )
{
m_pIEnumSpObjectTokens = NULL;
return;
}
ULONG ulTokensNumber = 0;
m_pIEnumSpObjectTokens->GetCount(&ulTokensNumber);//得到所有语音Token的个数
if(ulTokensNumber == 0)//检测该机器是否安装有语音包
{
MessageBox("该机器没有安装语音包!", "提示", MB_OK|MB_ICONWARNING);
return;
}
//<>
if(FAILED(CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_INPROC_SERVER, IID_ISpVoice, (void**)&m_pISpVoice)))
{
MessageBox("获取ISpVoice接口失败!", "提示", MB_OK|MB_ICONWARNING);
m_pISpVoice = NULL;
return;
}
ISpObjectToken *pISpObjectToken;
m_pIEnumSpObjectTokens->Item(0, &pISpObjectToken);
m_pISpVoice->SetVoice(pISpObjectToken);
m_pISpVoice->SetRate(3);//设置播放速度(-10到10)
m_pISpVoice->SetVolume(100);//设置音量大小 (0到100)
Speak();
//<>
CComboBox*pCom = (CComboBox*)GetDlgItem(IDC_COMBO1);
CString strVoicePackageName = _T("");
CString strTokenPrefixText = _T("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\");
WCHAR *pChar;
for(ULONG i=0; i<ulTokensNumber; i++)
{
m_pIEnumSpObjectTokens->Item(i, &pISpObjectToken);
pISpObjectToken->GetId(&pChar);
strVoicePackageName = pChar;
strVoicePackageName.Delete(0, strTokenPrefixText.GetLength());
pCom->InsertString(i, strVoicePackageName);
}
pCom->SetCurSel(0);//设置默认的语音包选择
}
复制代码
执行语音播报
void CMy123Dlg::Speak(CString sText)
{
if(!m_pISpVoice)
return;
if(sText.IsEmpty())
sText="请输入内容";
CSliderCtrl*pSlider = (CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
m_pISpVoice->SetRate(pSlider->GetPos());
m_pISpVoice->Speak(sText.AllocSysString(), SPF_ASYNC, NULL);//开始进行朗读
}
复制代码
调用语音播报
void CMy123Dlg::OnButton2()
{
//检测朗读内容是否为空
CString sText;
GetDlgItemText(IDC_EDIT1,sText);
Speak(sText);
}
复制代码
网页下载地址
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4