Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Microsoft Speech Platform

ISpRecoResult::GetAudio

ISpRecoResult::GetAudio creates an audio stream of the requested words from the audio data in the result object.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT GetAudio(</strong> <strong> ULONG</strong> <em>ulStartElement</em>, <strong> ULONG</strong> <em>cElements</em>, <a runat="server" href="jj127807(v=msdn.10).md"><strong>ISpStreamFormat</strong></a> <em>**ppStream</em> <strong>);</strong> </pre>

Parameters

  • ulStartElement
    [in] Value specifying from which element in the result data to start the audio stream.
  • cElements
    [in] Value specifying the total number of words.
  • ppStream
    [out] Address that will receive a pointer to an ISpStreamFormat object containing the audio data requested.

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG cElements is zero or the expected number of elements to count exceeds the number available.
E_POINTER ppStream is an invalid pointer.
SPERR_NO_AUDIO_DATA This result object does not have any audio data.
FAILED(hr) Appropriate error message.

Remarks

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

An application can find the time offsets for each element by examining the SPPHRASE object retrieved using ISpRecoResult::GetPhrase.

Example

The following code snippet illustrates the use ISpRecoResult::GetAudio to retrieve the retained audio.

`

// Declare local identifiers:
HRESULT                       hr = S_OK;
CComPtr<ISpRecoResult>        cpRecoResult;
CComPtr<ISpStreamFormat>      cpStreamFormat;
GUID                          formatId;
WAVEFORMATEX                  *pWaveFormatEx;

// ... Obtain a recognition result object from the recognizer ... hr = cpRecoResult->GetAudio(0, 0, &cpStreamFormat;);

if (SUCCEEDED(hr)) { // Check the format of the stream. hr = cpStreamFormat->GetFormat(&formatId;, &pWaveFormatEx;); }

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

`