Note

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

Microsoft Speech Platform

ISpPhrase::GetText

ISpPhrase::GetText retrieves elements from a text phrase.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT GetText(</strong> <strong> ULONG</strong> <em>ulStart</em>, <strong> ULONG</strong> <em>ulCount</em>, <strong> BOOL</strong> <em>fUseTextReplacements</em>, <strong> [annotation ("__deref_out")] LPWSTR</strong> **<em>ppszCoMemText</em>, <strong> [annotation ("__out_ecount_opt(1)")] BYTE</strong> *<em>pbDisplayAttributes</em> <strong>);</strong> </pre>

Parameters

  • ulStart
    [in] Specifies the first element in the text phrase to retrieve.
  • ulCount
    [in] Specifies the number of elements to retrieve from the text phrase.
  • fUseTextReplacements
    [in] Boolean value that indicates if replacement text should be used. 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 the data structure that contains the display text information. It is the caller's responsibility to call ::CoTaskMemFree to free the memory.
  • pbDisplayAttributes
    [out] Address of the SPDISPLAYATTRIBUTES enumeration that contains the text display attribute information. 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 might include SPAF_TWO_TRAILING_SPACES to inform the application without requiring extra text processing logic for the application.

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 parameters are invalid.
E_POINTER Invalid pointer.
E_OUTOFMEMORY Exceeded available memory.

Remarks

The text is the display text of the elements for the phrase.

Example

The following code snippet illustrates the use ISpPhrase::GetText to retrieve parts of the recognized phrase.

`

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

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

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

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

if (SUCCEEDED(hr)) { // Get the phrase's first 2 words, excluding replacements. hr = cpRecoResult->GetText(pPhrase->Rule.ulFirstElement, 2, FALSE, &pwszText;, NULL); }

if (SUCCEEDED (hr)) { // Do some more stuff. }

`