vs2008 speechSDK51的问题。
帮忙看下代码有什么错误。void CMyNotePage::OnBnClickedBtnSpeak()
{
// TODO: 在此添加控件通知处理程序代码
ISpVoice * pVoice = NULL;
//COM初始化:
if (FAILED(::CoInitialize(NULL)))
return ;
//获取ISpVoice:
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL,
IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
CComPtr<ISpStream> cpWavStream;
CComPtr<ISpStreamFormat> cpOldStream;
CSpStreamFormat OriginalFmt;
pVoice->GetOutputStream(&cpOldStream );
OriginalFmt.AssignFormat(cpOldStream);
//绑定文件:
hr = SPBindToFile( L"D:\\myRobo\\note\\output.wav",SPFM_CREATE_ALWAYS,
&cpWavStream,&OriginalFmt.FormatId(),
OriginalFmt.WaveFormatExPtr() );
if( SUCCEEDED( hr ) )
{
pVoice->SetOutput(cpWavStream,TRUE);
UpdateData();
ISpObjectToken* pToken = SpGetCurSelComboBoxToken(m_voice.m_hWnd);
ISpObjectToken* pOldToken;
HRESULT hr = pVoice->GetVoice( &pOldToken );
if (pOldToken != pToken)
{
hr = pVoice->SetVoice( pToken );
hr = pVoice->GetVoice( &pOldToken );
}
//CString WTX = L"<VOICE REQUIRED='NAME=VW Lily'/>" + m_s_note;
pVoice->SetVolume(50);
pVoice->SetRate(5);
hr = pVoice->Speak(m_s_note, SPF_ASYNC | SPF_IS_NOT_XML, 0);
pVoice->WaitUntilDone(INFINITE);
cpWavStream.Release();
pVoice->SetOutput(cpOldStream,FALSE);
pVoice->Release();
pVoice = NULL;
}
}
//释放COM资源:
::CoUninitialize();
}
运行时并没有报错,但是却又两个问题。
1. hr = pVoice->SetVoice( pToken ); (调试时 hr = S_OK)
hr = pVoice->GetVoice( &pOldToken );
设置语音,先设置,然后在获取。发现 pOldToken 没有任何变化,也就是说语音设置不成功。但是注释部分,通过字符串强行设置有效 //CString WTX = L"<VOICE REQUIRED='NAME=VW Lily'/>" + m_s_note;
2. hr = pVoice->Speak(m_s_note, SPF_ASYNC | SPF_IS_NOT_XML, 0);
pVoice->WaitUntilDone(INFINITE);
语音开始合成,然后等待合成结束。运行后,保存在L"D:\\myRobo\\note\\output.wav"的wav文件能够播放,但是在Speak运行过程中,却没有任何声音。也就是说语音合成成功了,但是并没有实时播放。
各位大侠,帮帮忙,谢谢了!