You are reading help file online using chmlib.com
|
ISpRecoResult::GetAlternates retrieves an array of pointers to ISpPhraseAlt objects containing alternate phrases.
HRESULT GetAlternates(
ULONG ulStartElement,
ULONG cElements,
ULONG ulRequestCount,
ISpPhraseAlt **ppPhrases,
ULONG *pcPhrasesReturned
);
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_POINTER | pcPhrasesReturned is an invalid pointer. However, ppPhrases does not contain ulRequestCount allocations. |
E_OUTOFMEMORY | Exceeded available memory. |
E_INVALIDARG | ulStartElement is not less than the number of elements in the owning interface. However, the number of expected elements exceeds the number of available elements in the owning interface. |
S_FALSE | No analyzer is present or there is no driver data. |
FAILED(hr) | Appropriate error message. |
The following code snippet illustrates the use ISpRecoResult::GetAlternates to retrieve and commit an alternate 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 text hr = pPhrase->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &pwszText, NULL); // Check hr // ... check the phrase's text... assume the phrase isn't a correct recognition // setup MY_MAX_ALTERNATES phrase alternate objects CComPtr<ISpPhraseAlt> pcpPhrase[MY_MAX_ALTERNATES]; ULONG ulCount; // get the top MY_MAX_ALTERNATES alternates to the entire recognized phrase hr = cpRecoResult->GetAlternates(pPhrase->Rule.ulFirstElement, pPhrase->Rule.ulCountOfElements, MY_MAX_ALTERNATES, pcpPhraseAlt, &ulCount); // Check hr // check each alternate in order of highest likelihood for (int i = 0; i < ulCount; i++) { hr = pcpPhraseAlt[i]->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &pwszAlternate, NULL); // Check hr // ... check if this alternate is more appropriate ... // if it is more appropriate, then commit the alternate if (fMoreAppropriate) { hr = pcpPhraseAlt[i]->Commit(); // Check hr } // free the alternate text if (pwszAlternate) ::CoTaskMemFree(pwszAlternate); } // free the initial phrase object if (pPhrase) ::CoTaskMemFree(pPhrase);
You are reading help file online using chmlib.com
|