使用之前需要先安裝中文語(yǔ)音包(男聲+女聲安裝包下載)
Voice.h文件
(頭文件包含的lib庫(kù)資源如果缺失,百度下載或我的資源)
#pragma once
#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable : 4005)
#include#pragma warning (pop)
#pragma warning (default : 4005)
#endif
#include#include#include#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"sapi.lib")
class CVoice
{public:
CVoice(void);
~CVoice(void);
private:
ISpVoice * pVoice ;
bool m_State;
void InitVoice();
void CloseVoice();
public:
void Speech(CString str,bool flag =true);
void SetRate(int rate);
void SetVoiceType(int voicetype); //設(shè)置1:男聲;2:女聲
};
Voice.cpp文件
#include "StdAfx.h"
#include "Voice.h"
CVoice::CVoice(void)
{m_State =false;
InitVoice();
}
CVoice::~CVoice(void)
{CloseVoice();
}
void CVoice::InitVoice()
{pVoice =NULL;
if (FAILED(::CoInitialize(NULL)))
return ;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{ISpObjectToken* pChineseToken;
WCHAR pszTokenId[] =L"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Speech\\Voices\\Tokens\\VW Liang";
SpGetTokenFromId(pszTokenId , &pChineseToken);
pVoice->SetVoice(pChineseToken);
pVoice->SetVolume(100);
pVoice->SetRate(1);
}
m_State =true;
}
void CVoice::CloseVoice()
{if(pVoice !=NULL)
{pVoice->Release();
pVoice = NULL;
}
if(m_State ==true)
::CoUninitialize();
}
void CVoice::SetRate(int rate)
{pVoice->SetRate(rate);
}
void CVoice::SetVoiceType(int voicetype)
{if (voicetype == 1)
{ISpObjectToken* pChineseToken;
// WCHAR pszTokenId[] =L"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Speech\\Voices\\Tokens\\VW Lily";
WCHAR pszTokenId[] =L"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Speech\\Voices\\Tokens\\VW Liang";
SpGetTokenFromId(pszTokenId , &pChineseToken);
pVoice->SetVoice(pChineseToken);
}
else
{ISpObjectToken* pChineseToken;
WCHAR pszTokenId[] =L"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Speech\\Voices\\Tokens\\VW Lily";
SpGetTokenFromId(pszTokenId , &pChineseToken);
pVoice->SetVoice(pChineseToken);
}
}
void CVoice::Speech(CString str,bool flag)
{USES_CONVERSION;
LPWSTR pwStr=new wchar_t[str.GetLength()+1];
wcscpy_s(pwStr,str.GetLength()+1,T2W((LPCTSTR)str));
if(flag ==true)
pVoice->Speak( pwStr, SPF_ASYNC, NULL);
else
pVoice->Speak( pwStr, SPF_DEFAULT, NULL);
delete[] pwStr;
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
文章名稱:C++桌面應(yīng)用中文語(yǔ)音包功能接口-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://jinyejixie.com/article4/ggeie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站內(nèi)鏈、企業(yè)建站、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容