Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
Microsoft Speech Platform
ISpRecoContext::SetAudioOptions
ISpRecoContext::SetAudioOptions sets the audio options for result objects from this recognition context. This method also enables or disables the retention of audio with result objects and can change the retained audio format.
<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT SetAudioOptions(</strong><a runat="server" href="jj127453(v=msdn.10).md"><strong>SPAUDIOOPTIONS</strong></a> <em>Options</em>, <strong>const GUID</strong> *<em>pAudioFormatId</em>, <strong>const</strong> <a runat="server" href="jj127893(v=msdn.10).md"><strong>WAVEFORMATEX</strong></a> *<em>pWaveFormatEx</em> <strong>);</strong> </pre>
Parameters
- Options
[in] Flag of type SPAUDIOOPTIONS indicating the option. It must be one of the following:Value Description SPAO_NONE Do not retain audio for results. SPAO_RETAIN_AUDIO Retain audio for all future results.
- pAudioFormatId
[in] The audio stream format id [of type GUID]. Usually this value is SPDFID_WaveFormatEx. If this value is NULL, the retained audio format will not be changed. Reset the retained audio format to the speech recognition engine's recognition format by setting this value to GUID_NULL and pWaveFormatEx to NULL. - pWaveFormatEx
[in] The audio stream wave format [of type WAVEFORMATEX]. This is only valid if *pAudioFormatId == SPFID_WaveFormatEx.
Return Values
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_INVALIDARG | Options is not one of the correct types, or the specified audio format is not valid. |
FAILED(hr) | Appropriate error message. |
Remarks
If the application specifies an audio format based onWAVEFORMATEX, but the SR engine and the audio input stream agree on an audio format that is not based onWAVEFORMATEX (for example, a custom audio object or format), ISpRecoContext::SetAudioOptions will return successfully, but will not retain the audio.
By default, the Speech Platform does not retain recognition audio.
By default, when an audio format is not specified, the audio will be retained in the same format that the SR engine used to perform the recognition.
Example
The following code snippet illustrates the use of ISpRecoContext::SetAudioOptions.
`
// Declare local identifiers: HRESULT hr = S_OK; CComPtr<ISpRecoContext> cpRecoContext; CComPtr<ISpStream> cpSpStream; CSpStreamFormat sfRetained;`// Activate retained audio settings with default // format (that is, SR engine recognition format). hr = cpRecoContext->SetAudioOptions(SPAO_RETAIN_AUDIO, &GUID;_NULL, NULL);
if (SUCCEEDED(hr)) { // Deactivate retained audio settings. hr = cpRecoContext->SetAudioOptions(SPAO_NONE, NULL, NULL); }
if (SUCCEEDED(hr)) { // Use the stream format helper to fill in the WAVEFORMATEX structure. CSpStreamFormat sfRetained(SPSF_24kHz16BitStereo, &hr;); }
if (SUCCEEDED(hr)) { // Change the settings to the selected stream format. hr = cpRecoContext->SetAudioOptions(SPAO_RETAIN_AUDIO, &sfRetained;.FormatId(), sfRetained.WaveFormatExPtr()); }
if (SUCCEEDED(hr)) { // Do stuff here. }