Please give me code demo by C or C++ : Speak file text !
HRESULT hr = S_OK;
CComPtr <ISpVoice> cpVoice;
CComPtr <ISpObjectToken> cpToken;
CComPtr <IEnumSpObjectTokens> cpEnum;
//Create a SAPI voice
hr = cpVoice.CoCreateInstance( CLSID_SpVoice );
//Enumerate voice tokens with attribute "Name=Microsoft Sam”
if(SUCCEEDED(hr))
{
hr = SpEnumTokens(SPCAT_VOICES, L"Name=Microsoft Sam", NULL, &cpEnum);
}
//Get the closest token
if(SUCCEEDED(hr))
{
hr = cpEnum ->Next(1, &cpToken, NULL);
}
//set the voice
if(SUCCEEDED(hr))
{
hr = cpVoice->SetVoice( cpToken);
}
//set the output to the default audio device
if(SUCCEEDED(hr))
{
hr = cpVoice->SetOutput( NULL, TRUE );
}
//Speak the text file (assumed to exist)
if(SUCCEEDED(hr))
{
hr = cpVoice->Speak( L”c:\\ttstemp.txt”, SPF_IS_FILENAME, NULL );
}
//Release objects
cpVoice.Release ();
cpEnum.Release();
cpToken.Release();
it is not run, maybe It have not file *.wav
?
Who help me run it !