ISpRecoGrammar::SetWordSequenceData (Windows CE 5.0)

Send Feedback

This method sets a word sequence buffer in the SR engine. The command and control grammar can refer to any subsequence of words in this buffer using the <TEXTBUFFER> tag, or the SPRULETRANS_TEXTBUFFER special transition type in ISpGrammarBuilder::AddRuleTransition().

See also ISpRecoGrammar::SetTextSelection for information on how to update the text selection information independent of the word sequence data.

See also ISpSREngine::SetWordSequenceData for information on how SAPI passes the word sequence data to the SR engine.

An application that has a text box could allow the user to speak commands into the text box to edit the text. One way to design this functionality would be to create a CFG which supports such commands as "cut the text *", "bold the text *", or "italicize the words *". The grammar would then use a TEXTBUFFER tag in place of the * which would allow the SR engine to recognize the text buffer information. At run time, the application would update the SR engine's view of the text buffer using SetWordSequenceData. So if a user had the text helloworld in the text box, the SR engine could recognize "bold the text world".

HRESULT SetWordSequenceData(const WCHAR* pText,ULONG cchText,const SPTEXTSELECTIONINFO* pInfo);

Parameters

  • pText
    [in] Pointer to the text to search for possible word sequences. The buffer is double NULL-terminated. The whole buffer can be separated into different groups by '\0'. Any sub-sequence of words in the same group is recognizable, while any sub-sequence of words across different groups is not recognizable. A word can be in simple format or complex format: /disp/lex/pron. It is up to the SR engine to perform word breaking and text normalization for improved performance. For example: If the buffer resembles: "Now play this\0new game\0\0", then "Now play" is recognizable, while "this new game" is not recognizable.
  • cchText
    [in] Number of characters in the text specified by pText.
  • pInfo
    [in, optional] Pointer to an SPTEXTSELECTIONINFO structure containing selection information. If NULL, then the SR engine will use the entire contents of pText.

Return Values

The following table shows the possible return values.

Value Description
S_OK Function completed successfully.
E_INVALIDARG One or more arguments are invalid.
FAILED(hr) Appropriate error message.

Example

The following code snippet illustrates how an application could send a text buffer to the SR engine using this method.

HRESULT hr = S_OK;
// place the contents of text buffer into pwszCoMem and the length of the text
in cch
SPTEXTSELECTIONINFO tsi;
tsi.ulStartActiveOffset = 0;
tsi.cchActiveChars = cch;
tsi.ulStartSelection = 0;
tsi.cchSelection = cch;
pwszCoMem2 = (WCHAR *)CoTaskMemAlloc(sizeof(WCHAR) * (cch + 2));
if (SUCCEEDED(hr) && pwszCoMem2)
{
    // SetWordSequenceData requires double NULL terminator.
    memcpy(pwszCoMem2, pwszCoMem, sizeof(WCHAR) * cch);
    pwszCoMem2[cch] = L'\0';
    pwszCoMem2[cch+1] = L'\0';
    // set the text buffer data
    hr = cpRecoGrammar->SetWordSequenceData(pwszCoMem2, cch + 2, &tsi);
    // Check hr
    CoTaskMemFree(pwszCoMem2);
}
CoTaskMemFree(pwszCoMem);
// the SR engine is now capable of recognizing the contents of the text buffer 

Requirements

OS Versions: Windows CE .NET 4.1 and later.
Header: Sapi.h, Sapi.idl.
Link Library: Sapilib.lib.

See Also

ISpRecoGrammar | SAPI Interfaces

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.