winXP控制面板TTS语音打不开卡顿-SDK开发无法播放中文解决方法-MFC调用代码
winXP控制面板TTS语音打不开卡顿解决方法
下载安装:
http://www.bkill.com/download/153.html
http://d3.jnqcjy.ltd:806/1208/speechsdk51.rar
1.安装Microsoft Speech SDK 5.1.msi
2. 安装Microsoft Speech SDK 5.1 Language Pack.msi
打开“C:\Windows\Inf”,右键单击文件“sapi5.inf
https://wenku.baidu.com/view/71e02f4733687e21af45a9b5.html
#include "StdAfx.h" #include "Class_PlayAudio.h" Class_PlayAudio::Class_PlayAudio(void) { } Class_PlayAudio::~Class_PlayAudio(void) { } void Class_PlayAudio::ReadAudioConfig() { char szReadText[100]; try { GetPrivateProfileStringA("Config", "RepeatTimes", "admin", szReadText, sizeof(szReadText), "./AudioConfig.ini"); PlayAudio_RepeatTimes= _bstr_t(szReadText).operator TCHAR *(); GetPrivateProfileStringA("Config", "PlayInterval", "admin", szReadText, sizeof(szReadText), "./AudioConfig.ini"); PlayAudio_PlayInterval= _bstr_t(szReadText).operator TCHAR *(); GetPrivateProfileStringA("Config", "PlayContent", "admin", szReadText, sizeof(szReadText), "./AudioConfig.ini"); PlayAudio_PlayContent= _bstr_t(szReadText).operator TCHAR *(); } catch(CFileException ex) { MessageBox(L"读取文件失败"); } } void Class_PlayAudio::MSSSpeak(LPCTSTR speakContent)// speakContent为LPCTSTR型的字符串,调用此函数即可将文字转为语音 { ISpVoice *pVoice = NULL; //初始化COM接口 if (FAILED(::CoInitialize(NULL))) //MessageBox(NULL, (LPCWSTR)L"COM接口初始化失败!",(LPCWSTR)L"提示", MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2); MessageBox(L"COM初始化失败"); //获取SpVoice接口 HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&pVoice); ISpObjectToken * pSpObjectToken = NULL; if (SUCCEEDED(SpFindBestToken(SPCAT_VOICES, L"language=804", NULL, &pSpObjectToken)))//804代表中文 //if (SUCCEEDED(SpFindBestToken(SPCAT_VOICES, L"language=409", NULL, &pSpObjectToken)))//804代表中文 //if (SUCCEEDED(hr)) { pVoice->SetVolume((USHORT)100); //设置音量,范围是 0 -100 pVoice->SetRate(0); //设置速度,范围是 -10 - 10 hr = pVoice->Speak(speakContent, 0, NULL); pVoice->Release(); pVoice = NULL; } //释放com资源 ::CoUninitialize(); } //void Class_PlayAudio::OnBnClickedButton1() //{ // // TODO: 在此添加控件通知处理程序代码 // //MSSSpeak(L"大家好"); // MSSSpeak(L"nice大家好"); // //}
欢迎讨论,相互学习。
cdtxw@foxmail.com