In a real world speech application, one might need to store the audio data from a recognition, to check after that if what the user said is the same as what the application recognized.
It's pretty easy to do this using just SAPI objects (no other external goop).
Apparently one can get the audio data just in case of a successful recognition.
From the point of view of the code, one should put the following code in the SPEI_RECOGNITION case from the previous post, and then one could use this functionality.
CComPtr pSpVoice;
//create a TTS object
hr = pSpVoice.CoCreateInstance(CLSID_SpVoice);
//check hr
CSpStreamFormat cAudioFmt;
hr = cAudioFmt.AssignFormat(SPSF_11kHz16BitMono);
//check hr
CComPtr pSpStream;
hr = SPBindToFile("D:\temp.wav" , SPFM_CREATE_ALWAYS, &pSpStream, &cAudioFmt.FormatId(),cAudioFmt.WaveFormatExPtr() );
//check hr
//set TTS output to wav file
hr = pSpVoice->SetOutput( pSpStream, TRUE );
//check hr
SPPHRASE* pPhrase = 0;
//get a phrase object (this contains audio data)
hr = pRecoResult->GetPhrase(&pPhrase);
//check hr
//get audio
hr = pRecoResult->GetAudio(0, pPhrase->Rule.ulCountOfElements, &pStreamFormat);
//check hr
//speak audio data to file
hr = pSpVoice->SpeakStream(pStreamFormat, SPF_DEFAULT, NULL);
//check hr
//clean up
pSpStream->Close();
pSpStream.Release();
pSpVoice.Release();
Have fun!
Niciun comentariu:
Trimiteți un comentariu