ISpPhrase::GetSerializedPhrase
ISpPhrase::GetSerializedPhrase returns the phrase information in serialized form.
HRESULT GetSerializedPhrase(
SPSERIALIZEDPHRASE **ppCoMemPhrase
;)
Parameters
- ppCoMemPhrase
- [out] Address of a pointer which will be initialized to point to the serialized phrase data. The block of memory is created by CoTaskMemAlloc and must be manually freed with CoTaskMemFree when no longer needed.
Return values
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_POINTER | ppCoMemPhrase is invalid or bad. |
SPERR_UNINITIALIZED | Phrase is uninitialized. |
E_OUTOFMEMORY | Exceeded available memory. |
Remarks
The caller passes in the address of a pointer which is initialized to point to a block of memory which is allocated using CoTaskMemAlloc. It is the caller's responsibility to call CoTaskMemFree to free this object. The structure returned is defined to be a SPSERIALIZEDPHRASE. However, the actual size of the block is contained in (*ppCoMemPhrase)->ulSerializedSize. This size includes the size of the SPSERIALIZEDPHRASE structure.
An application that will not need recognition alternates or retained audio and needs to save space, can serialize only the phrase information (e.g., phrase text, rule name, SR engine ID, etc.) by calling ISpPhrase::Discard.
Example
The following code snippet illustrates the use ISpRecoResult::GetSerializedPhrase as inherited from ISpPhrase to serialize only the phrase portion of a result object.
// Declare local identifiers:
HRESULT hr = S_OK;
CComPtr<ISpRecoResult> cpRecoResult;
SPSERIALIZEDPHRASE *pSerializedPhrase = NULL;
// ... Obtain a recognition result object from the recognizer ...
// Get the recognized serialized phrase object.
hr = cpRecoResult->GetSerializdPhrase(&pSerializedPhrase;);
if (SUCCEEDED (hr))
{
// Do something with it.
}