a Microsoft sample page에서 SAPI 샘플을 실행하려고합니다. 나는 (VS2010)와 응용 프로그램을 실행할 때SAPI (Microsoft Speech API) CoCreateInstance failed
,이 라인은 실패
hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
시간 오류 코드를 반환하고 다른 모든 코드가 실행되지 않습니다.
내가 왜 틀렸는 지 모르겠다. 왜냐하면 나는 그 페이지에서 샘플 코드를 올바르게 사용하고 이전에는이 API를 사용하지 않았기 때문이다.
이것은 내 전체 main.cpp 파일입니다. 내가 뭘 놓치고있어?
#include "stdafx.h"
#include <sapi.h>
#include <sphelper.h>
#include <atlcomcli.h>
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = S_OK;
CComPtr <ISpVoice> cpVoice;
CComPtr <ISpStream> cpStream;
CSpStreamFormat cAudioFmt;
//Create a SAPI Voice
hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
//Set the audio format
if(SUCCEEDED(hr))
{
hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
}
//Call SPBindToFile, a SAPI helper method, to bind the audio stream to the file
if(SUCCEEDED(hr))
{
hr = SPBindToFile(L"c:\\ttstemp.wav", SPFM_CREATE_ALWAYS,
&cpStream, & cAudioFmt.FormatId(),cAudioFmt.WaveFormatExPtr());
}
//set the output to cpStream so that the output audio data will be stored in cpStream
if(SUCCEEDED(hr))
{
hr = cpVoice->SetOutput(cpStream, TRUE);
}
//Speak the text "hello world" synchronously
if(SUCCEEDED(hr))
{
hr = cpVoice->Speak(L"Hello World", SPF_DEFAULT, NULL);
}
//close the stream
if(SUCCEEDED(hr))
{
hr = cpStream->Close();
}
//Release the stream and voice object
cpStream.Release();
cpVoice.Release();
return 0;
}
HRESULT를 오류 코드로 사용한다고했지만 코드의 내용을 말하지 않았습니다. –
@AdrianMcCarthy 당신은 절대적으로 옳습니다. 사과 (늦은 시간이었고 여자 친구 생일 파티에 집으로 돌아왔다.). 다음에는 더 조심해. – Jepessen