Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Microsoft Speech Platform

ISpRecoContext::DeserializeResult

ISpRecoContext::DeserializeResult creates a new result object from a serialized result.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT DeserializeResult(</strong> <strong>const</strong> <a runat="server" href="jj127886(v=msdn.10).md"><strong>SPSERIALIZEDRESULT</strong></a> <em>*pSerializedResult</em>, <a runat="server" href="jj127790(v=msdn.10).md"><strong>ISpRecoResult</strong></a> **<em>ppResult</em> <strong>);</strong> </pre>

Parameters

  • pSerializedResult
    [in] Pointer to a serialized result. See also SPSERIALIZEDRESULT
  • ppResult
    [out] The unserialized result object. The application must call IUnknown::Release when finished using the ISpRecoResult reference.

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG pSerializedResult is invalid or bad.
E_POINTER ppResult is invalid or bad.
E_OUTOFMEMORY Exceeded available memory.
FAILED(hr) Appropriate error message.

Remarks

After deserializing the ISpRecoResult object, the application can retrieve alternates for the RecoResult, retrieve the retained audio, or examine the recognition.

The same speech recognition (SR) engine that was originally used to generate the ISpRecoResult ISpRecoResult object (or recognition) must be the same SR engine that is associated with the ISpRecoContext that called ::DeserializeResult (see SPPHRASE.SREngineID). The SR engine requirement ensures that the SR engine is capable of recognizing the original phrase, and that it understands any SR engine private result data (see SPPHRASE.ulSREnginePrivateDataSize).

Example

The following code snippet illustrates the use of ISpRecoContext::Deserialize to deserialize a previously serialized result object.

`

// Declare local identifiers:
HRESULT                    hr = S_OK;
CComPtr<ISpRecoResult>     cpRecoResult;
CComPtr<ISpRecoResult>     cpRecoResultNew;
CComPtr<IStream>           cpStreamWithResult;
CComPtr<ISpRecoContext>    cpRecoContext;
SPSERIALIZEDRESULT*        pSerializedResult = NULL;
ULONG                      cbWritten = 0;
ULONG                      ulSerializedSize = 0;
LARGE_INTEGER              liseek;
LARGE_INTEGER              li;

// ... Obtain a recognition result object from the recognizer ... hr = CreateStreamOnHGlobal(NULL, true, &cpStreamWithResult;);

if (SUCCEEDED(hr)) { // Serialize result to memory. hr = cpRecoResult->Serialize(&pSerializedResult;); }

if (SUCCEEDED(hr)) { // Serialize to a stream pointer. hr = cpStreamWithResult->Write(pSerializedResult, pSerializedResult->ulSerializedSize, &cbWritten;); }

if (SUCCEEDED(hr)) { // Free the serialized result. if (pSerializedResult) ::CoTaskMemFree(pSerializedResult);

// Commit the stream changes. hr = cpStreamWithResult->Commit(STGC_DEFAULT); }

if (SUCCEEDED(hr)) { // ... Persist stream to disk, network share, etc ... // ... Shutdown application ... // ... Restart application and get the persisted stream ...

// Reset the stream seek pointer to the start before deserialization. li.QuadPart = 0; hr = cpStreamWithResult->Seek(li, STREAM_SEEK_SET, NULL); }

if (SUCCEEDED(hr)) { // Find the size of the stream. hr = cpStreamWithResult->Read(&ulSerializedSize;, sizeof(ULONG), NULL); }

if (SUCCEEDED(hr)) { // Reset the seek pointer. liseek.QuadPart = 0 - sizeof(ULONG); hr = cpStreamWithResult->Seek(liseek, STREAM_SEEK_CUR, NULL); }

if (SUCCEEDED(hr)) { // Allocate the memory for the result. pSerializedResult = (SPSERIALIZEDRESULT*)::CoTaskMemAlloc(ulSerializedSize);

// Check pSerializedResult in case out "out-of-memory".

// Copy the stream into a serialized result object. hr = cpStreamWithResult->Read(pSerializedResult, ulSerializedSize, NULL); }

if (SUCCEEDED(hr)) { // Deserialize result from memory. hr = cpRecoContext->DeserializeResult(pSerializedResult, &cpRecoResultNew;); }

if (SUCCEEDED(hr)) { // Free the pSerializedResult memory. if (pSerializedResult) CoTaskMemFree(pSerializedResult); }

// As long as the same engine was used to generate original // result object, as is now being used, applications can // now get alternates for the cpRecoResultNew's phrase.

`