Compartir a través de


ISpPhraseBuilder::InitFromSerializedPhrase (SAPI 5.3)

Microsoft Speech API 5.3

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
S_OK
E_INVALIDARG
FAILED(hr)

Example

The following code fragment demonstrates InitFromSerializedPhrase.

  
// Declare local identifiers:
HRESULT                      hr = S_OK;
CComPtr<ISpRecoResult>       RecoResult;
CComPtr<ISpPhraseBuilder>    cpPhraseBuilder;
CComPtr<ISpStream>           cpStream;
SPSERIALIZEDPHRASE           *pSerializedPhrase=NULL;
LARGE_INTEGER                liZero = {0,0};
ULONG                        ulSerializedSize = 0;
LARGE_INTEGER                liseek;

// Bind audio stream to specified file (note
// that SerializedPhrase.sp is a dummy file).
hr = SPBindToFile(L"SerializedPhrase.sp", SPFM_OPEN_READONLY, &cpStream;, NULL, NULL, SPFEI_ALL_EVENTS);

if (SUCCEEDED(hr))
{
   hr = cpStream->Seek(liZero, STREAM_SEEK_SET, NULL);
}

if (SUCCEEDED(hr))
{
   hr = cpStream->Read(&ulSerializedSize;, sizeof(ULONG), NULL);
}

if (SUCCEEDED(hr))
{
   // Need to seek back and read the whole chunk of data in:
   liseek.QuadPart  -= sizeof(ULONG);
   hr = cpStream->Seek(liseek, STREAM_SEEK_CUR, NULL);
}

if (SUCCEEDED(hr))
{
   pSerializedPhrase = (SPSERIALIZEDPHRASE*)::CoTaskMemAlloc(ulSerializedSize);
}

if (SUCCEEDED(hr) && pSerializedPhrase)
{
   hr = cpStream->Read(pSerializedPhrase, ulSerializedSize, NULL);
}

if (SUCCEEDED(hr) && pSerializedPhrase)
{
   hr = cpPhraseBuilder.CoCreateInstance(CLSID_SpPhraseBuilder);
}

if (SUCCEEDED(hr))
{
   hr = cpPhraseBuilder->InitFromSerializedPhrase(pSerializedPhrase);
}

if (SUCCEEDED(hr))
{
   ::CoTaskMemFree(pSerializedPhrase);
}