ISpRecoResult::ScaleAudio (Windows CE 5.0)
This method converts an existing audio stream into a different audio format. 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.
HRESULT ScaleAudio(const GUID* pAudioFormatId,const WAVEFORMATEX* pWaveFormatEx);
Parameters
- pAudioFormatId
[in] Pointer to the data format identifier. Typically, this value is SPDFID_WaveFormatEx. - pWaveFormatEx
[in] Pointer to a WAVEFORMATEX structure containing the audio format to which to convert. This value must be NULL if pAudioFormatId is not specified as SPDFID_WaveForamtEx.
Return Values
The following table shows the possible 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
When performing a scaling with a compressed format it is possible to introduce small rounding errors, because the content of the audio is not used to perform the conversion.
Performing scaling between some compressed formats, and some other compressed formats is not supported by the SAPI format converter (See the Remarks section for ISpStreamFormatConverter).
A related enumeration is SPSTREAMFORMAT, which defines SAPI-supported stream formats. A related class is CSpStreamFormat, which manages SAPI-supported stream formats and WAVEFORMATEX structures.
Example
The following code snippet illustrates the use this method to scale the audio to a low quality format before serialization to the disk (to save space).
HRESULT hr = S_OK;
// ... obtain a recognition result object from the recognizer...
// create a format helper with a very low quality format
CSpStreamFormat ScaleFormat(SPSF_8kHz8BitMono, &hr);
// Check hr
hr = cpRecoResult->ScaleAudio(&(ScaleFormat.FormatId()),
ScaleFormat.WaveFormatExPtr());
// Check hr
// get a result serialization pointer
SPSERIALIZEDRESULT* pSerializedResult;
// serialize the result
hr = cpRecoResult->Serialize(&pSerializedResult);
// Check hr
// ... write pSerializedResult to the disk
Requirements
OS Versions: Windows CE .NET 4.1 and later.
Header: Sapi.h, Sapi.idl.
Link Library: Sapilib.lib.
See Also
ISpRecoResult | SAPI Interfaces
Send Feedback on this topic to the authors