ISpRecoResult::SpeakAudio (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3


ISpRecoResult::SpeakAudio retrieves and speaks the specified audio. This combines two other methods; first calling ISpRecoResult::GetAudio and then calling ISpVoice::SpeakStream on the parent recognition context.

HRESULT SpeakAudio(
   ULONG    ulStartElement,
   ULONG    cElements,
   DWORD    dwFlags,
   ULONG   *pulStreamNumber


[in] Value specifying with which element to start.
[in] Value specifying the number of elements contained in the stream. A value of zero speaks all elements.
[in] Value indicating the attributes of the text stream. These values are contained in the SPEAKFLAGS enumeration.
[optional, out] Address of a variable containing the stream number information. If NULL, the stream number will not be retrieved.

Return values

S_OKFunction completed successfully.
SPERR_NO_AUDIO_DATAResult does not contain audio data.
E_POINTERpulStreamNumber is a non-NULL, bad pointer.
FAILED(hr)Appropriate error message.
Return values may also be those from ISpVoice::SpeakStream.


Even if there are no elements, that is, ulStartElement = 0 and cElements = 0, the audio will still be spoken. These are unrecognized results that have no elements, but do have audio.

If the application did not activate retained audio (see ISpRecoContext::SetAudioOptions), or make a previous call to ISpPhrase::Discard and eliminate the retained audio, ::SpeakAudio will fail with SPERR_NO_AUDIO_DATA.


The following code snippet illustrates the use of ISpRecoResult::SpeakAudio.

// Declare local identifiers:
HRESULT                       hr = S_OK;
CComPtr<ISpRecoResult>        cpRecoResult;
ULONG                         ulStreamNum = 1;

// ... Get a recognition result object from the SR engine ...

// Replay the user's spoken audio to the user.
hr = cpRecoResult->SpeakAudio(0, 0, 0, &ulStreamNum;);

if (SUCCEEDED(hr))
   // Do stuff here.