Share via


ISpPhrase::GetPhrase (SAPI 5.4)

Microsoft Speech API 5.4

ISpPhrase::GetPhrase

ISpPhrase::GetPhrase retrieves data elements associated with a phrase.

  
    HRESULT GetPhrase(SPPHRASE   **ppCoMemPhrase
);

Parameters

  • ppCoMemPhrase
    [out] Address of a pointer to an SPPHRASE data structure receiving the phrase information. May be NULL if no phrase is recognized. If NULL, no memory is allocated for the structure. It is the caller's responsibility to call CoTaskMemFree to free the object; however, the caller does not need to call CoTaskMemFree on each of the elements in SPPHRASE.

Return values

Value
S_OK
E_POINTER
E_OUTOFMEMORY

Returned data includes all elements associated with this phrase.

Example

The following code snippet illustrates the use of ISpRecoResult::GetPhrase as inherited from ISpPhrase to retrieve the recognized text, and display the rule recognized and the phrase.

  
// Declare local identifiers:
HRESULT                   hr = S_OK;
CComPtr<ISpRecoResult>    cpRecoResult;
SPPHRASE                  *pPhrase;
WCHAR                     *pwszText;
HWND                      hwndParent;

// ... Obtain a recognition result object from the recognizer ...

// Get the recognized phrase object.
hr = cpRecoResult->GetPhrase(&pPhrase;);

if (SUCCEEDED (hr))
{
   // Get the phrase's text.
   hr = cpRecoResult->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &pwszText;, NULL);
}

if (SUCCEEDED(hr))
{
   // Display the recognized text and the rule name in a message box.
   MessageBoxW(hwndParent, pwszText, pPhrase->Rule.pszName, MB_OK);
}