ISpPhrase::GetPhrase (SAPI 5.3)

Microsoft Speech API 5.3


ISpPhrase::GetSerializedPhrase returns the phrase information in serialized form.

    HRESULT GetSerializedPhrase(SPSERIALIZEDPHRASE   **ppCoMemPhrase


  • 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



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.) by calling ISpPhrase::Discard.


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.