Share via


Note

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

Microsoft Speech Platform

ISpRecoResult::ScaleAudio

ISpRecoResult::ScaleAudio converts an existing audio stream into a different audio format.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT ScaleAudio(</strong> <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

  • pAudioFormatId
    [in] Address of the data format identifier. Typically, this value is SPDFID_WaveFormatEx.
  • pWaveFormatEx
    [in] Address of the WAVEFORMATEX structure that contains the audio format to convert to. This value must be NULL if pAudioFormatId is not specified as SPDFID_WaveForamtEx.

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG Either pAudioFormatId or pWaveFormatEx is invalid or bad.
SPERR_NO_AUDIO_DATA Audio stream is unavailable.
SPERR_UNSUPPORTED_FORMAT The engine format is non-waveformatex and the retained format the same format.
E_OUTOFMEMORY Exceeded available memory.
FAILED(hr) Appropriate error message.

Remarks

Use the ISpPhrase::Discard method to completely discard audio data associated with a result object.

The application can also set the default retained audio format for the ISpRecoResult object by calling ISpRecoContext::SetAudioOptions. Calling ::SetAudioOptions will only apply to all subsequent recognitions, not the current ISpRecoResult object.

When performing a scaling with a compressed format, it is possible to introduce small rounding errors, since the content of the audio is not used to perform the conversion.

Scaling between certain compressed formats is not supported by the Speech Platform's format converter (See the Remarks section for ISpStreamFormatConverter).

Example

The following code snippet illustrates the use ISpRecoResult::ScaleAudio to scale the audio to a low quality format before serialization to the disk (to save space).

`

// Declare local identifiers:
HRESULT                       hr = S_OK;
CComPtr<ISpRecoContext>       cpRecoContext;
CComPtr<ISpRecoResult>        cpRecoResult;
SPSERIALIZEDRESULT*           pSerializedResult = NULL;

// ... Obtain a recognition result object from the recognizer ...

// Create a format helper with a very low quality format. CSpStreamFormat ScaleFormat(SPSF_8kHz8BitMono, &hr;);

if (SUCCEEDED(hr)) { hr = cpRecoResult->ScaleAudio(&;(ScaleFormat.FormatId()), ScaleFormat.WaveFormatExPtr()); }

if (SUCCEEDED(hr)) { // Serialize the result. hr = cpRecoResult->Serialize(&pSerializedResult;); }

if (SUCCEEDED(hr)) { // Write pSerializedResult to the disk. }

`

Remarks

For information about the stream formats supported by the Speech Platform, see SPSTREAMFORMAT.

See the CSpStreamFormat class for information about managing stream formats and WAVEFORMATEX structures.