You are reading help file online using chmlib.com
|
ISpRecoGrammar::SetWordSequenceData 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().
HRESULT SetWordSequenceData(
const WCHAR *pText,
ULONG cchText,
const SPTEXTSELECTIONINFO *pInfo
);
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_INVALIDARG | One or more parameters are invalid. |
FAILED(hr) | Appropriate error message. |
An application that has a text box could enable 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 enable 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 "hello world" in the text box, the SR engine could recognize "bold the text world".
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.
The SR engine must support text buffer features. Check for the presence of the TextBuffer attribute for the SR engine. Microsoft SR ASR engines support these features although there is no requirement that other manufacturers engines need to. See Recognizers in Object Tokens and Registry Settings for more information.
The following code snippet illustrates how an application could send a text buffer to the SR engine using ISpRecoGrammar::SetWordSequenceData.
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
You are reading help file online using chmlib.com
|