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. The phrase structure can be saved to a file, and later restored by calling ISpPhraseBuilder::InitFromSerializedPhrase.
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.).
Example
The following code snippet illustrates the use ISpRecoResult::GetSerializedPhrase as inherited from ISpPhrase to serialize only the phrase portion of a result object.
HRESULT hr = S_OK; // ... obtain a recognition result object from the recognizer... SPSERIALIZEDPHRASE* pSerializedPhrase = NULL; // get the recognized phrase object hr = cpRecoResult->GetSerializdPhrase(&pSerializedPhrase); // Check hr