ISpPhraseBuilder::InitFromSerializedPhrase

Microsoft Speech SDK

The Microsoft.com Speech website Microsoft Speech SDK SAPI 5.1

ISpPhraseBuilder::InitFromSerializedPhrase

ISpPhraseBuilder::InitFromSerializedPhrase initializes a phrase from a serialized phrase.

HRESULT InitFromSerializedPhrase(
   const   SPSERIALIZEDPHRASE   *pPhrase
);

Parameters

pPhrase
Address of the SPSERIALIZEDPHRASE structure that contains the phrase information.

Return values

Value Description
S_OK Function completed successfully.
E_INVALIDARG pSrcPhrase or pSrcPhrase->cbSerializedSize is invalid or bad.
FAILED(hr) Appropriate error message.

Example

The following code fragment demonstrates InitFromSerializedPhrase.

HRESULT hr;
CComPtr<ISpRecoResult>       RecoResult;
CComPtr<ISpPhraseBuilder>    pPhraseBuilder;
SPSERIALIZEDPHRASE           *pSerializedPhrase=NULL;
CComPtr<ISpStream>           cpStream;

LARGE_INTEGER   liZero = {0,0};
hr = SPBindToFile(L"SerializedPhrase.sp", SPFM_OPEN_READONLY, &cpStream;, NULL, NULL, SPFEI_ALL_EVENTS);
if (hr == S_OK)
{
   hr = cpStream->Seek(liZero, STREAM_SEEK_SET, NULL);
   ULONG ulSerializedSize = 0;
   hr = cpStream->Read(&ulSerializedSize;, sizeof(ULONG), NULL);
   if (SUCCEEDED(hr))
   {
	//We need to seek back and read the whole chunk of data in.
	LARGE_INTEGER liseek;
	liseek.QuadPart  -= sizeof(ULONG);
	hr = cpStream->Seek(liseek, STREAM_SEEK_CUR, NULL);

	pSerializedPhrase = (SPSERIALIZEDPHRASE*)::CoTaskMemAlloc(ulSerializedSize);
	if (SUCCEEDED(hr) && pSerializedPhrase)
	{
		hr = cpStream->Read(pSerializedPhrase, ulSerializedSize, NULL);
	}
	if (SUCCEEDED(hr))
	{
		CComPtr<ISpPhraseBuilder> cpPhraseBuilder;
                hr = cpPhraseBuilder.CoCreateInstance(CLSID_SpPhraseBuilder);
                if (SUCCEEDED(hr))
                {
   	       	    hr = cpPhraseBuilder->InitFromSerializedPhrase(pSerializedPhrase);
                }
	}
	::CoTaskMemFree( pSerializedPhrase );
    }
}