Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This method sets the current text selection and insertion point information. See also ISpRecoGrammar::SetWordSequenceData for information on how to set the text data. See also ISpSREngine::SetTextSelection for information on how SAPI passes the text selection info to the SR engine.
HRESULT SetTextSelection(const SPTEXTSELECTIONINFO* pInfo);
Parameters
- pInfo
[in] Pointer to an SPTEXTSELECTIONINFO structure containing the text selection and insertion point information.
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. |
Remarks
An application that has a text box might allow the user to speak commands into the text box to edit the text. One way to design this functionality is to create a CFG that supports such commands as "cut the text *", "bold the text *", or "italicize the words *". In this case, the grammar uses a TEXTBUFFER tag in place of the * to allow the SR engine to recognize the text buffer information. At run time, when the user highlights a selection of text and the text selection using SetTextSelection, the application updates the SR engine view of the text buffer using ISpRecoGrammar::SetWordSequenceData.
The application should change the active text selection when the text highlight changes, rather than the entire word sequence data. This ensures that the SR engine has a textual context to help the recognition language model.
Example
The following code snippet illustrates how to use this method after sending a text buffer to the SR engine.
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, NULL);
// Check hr
// set the text selection information
hr = cpRecoGrammar->SetTextSelection(&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