Share via


ISpPhrase::GetText

Other versions of this page are also available for the following:

Windows Mobile Not SupportedWindows Embedded CE Supported

8/28/2008

This method gets elements from a text phrase.

Syntax

HRESULT GetText(
  ULONG ulStart,
  ULONG ulCount,
  BOOL fUseTextReplacements,
  WCHAR** ppszCoMemText,
  BYTE* pbDisplayAttributes
);

Parameters

  • ulStart
    [in] First element in the text phrase to retrieve.
  • ulCount
    [in] Number of elements to retrieve from the text phrase.
  • fUseTextReplacements
    [in] Value indicating if replacement text should be used. Set this value to TRUE to use replacement text, and to FALSE otherwise. An example of a text replacement is saying "write new check for twenty dollars" and retrieving the replaced text as "write new check for $20".
  • ppszCoMemText
    [out] Address of a pointer to display text information. It is the caller's responsibility to call CoTaskMemFree to free the memory.
  • pbDisplayAttributes
    [out] Address of a pointer to text display attribute information. Possible information types are defined by the SPDISPLAYATTRIBUTES enumeration. Text display attribute information can be used by the application to display the text to the user in a reasonable manner. For example, speaking "hello comma world period" includes a trailing period, so the recognition may include SPAF_TWO_TRAILING_SPACES to inform the application without requiring extra text processing logic for the application.

Return Value

The following table shows the possible return values.

Value Description

S_OK

Function completed successfully.

S_FALSE

A phrase that does not contain text or ppszCoMemText is NULL.

E_INVALIDARG

One or more arguments are invalid.

E_POINTER

Invalid pointer.

E_OUTOFMEMORY

Exceeded available memory.

Example

The following code snippet illustrates the use this method to retrieve parts of the recognized phrase.

HRESULT hr = S_OK;
//... obtain a recognition result object from the recognizer...
// get the recognized phrase object
hr = cpRecoResult->GetPhrase(&pPhrase);
// Check hr
// get the phrase's entire string, including replacements
hr = pPhrase->GetText(SP_GETWHOLEPHRASE, 
                      SP_GETWHOLEPHRASE, 
                      TRUE, 
                      &pwszText,
                      NULL);
// Check hr
// get the phrase's first 2 words, excluding replacements
hr = pPhrase->GetText(pPhrase->Rule.ulFirstElement, 
                      2, 
                      FALSE, 
                      &pwszText,
                      NULL);

Requirements

Header sapi.h, sapi.idl
Library sapilib.lib
Windows Embedded CE Windows CE .NET 4.1 and later

See Also

Reference

ISpPhrase
SAPI Interfaces