ISpPhraseAlt::Commit (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3


ISpPhraseAlt::Commit replaces a section of the parent phrase to which the alternate corresponds.

HRESULT  Commit  ( void );



Return values

S_OKFunction completed successfully.
SPERR_NOT_FOUNDThe alternate object is not related to a valid parent phrase object.


After an alternate has been committed, the parent phrase will be modified to reflect the substitution.

Upon committing the alternate phrase, the SR engine also has the ability to update its language model to improve future recognitions of the same or similar phrases (see ISpSRAlternates::Commit).


The following code snippet illustrates the use ISpPhraseAlt::Commit to commit an alternate phrase.

// Declare local identifiers:
HRESULT                    hr = S_OK;
const USHORT               MY_MAX_ALTERNATES = 10;
CComPtr<ISpRecoResult>     cpRecoResult;
CComPtr<ISpPhrase>         cpPhrase;
CComPtr<ISpPhraseAlt>      pcpPhraseAlt[MY_MAX_ALTERNATES];
SPPHRASE                   *pPhrase;
WCHAR                      *pwszText;
WCHAR                      *pwszAlternate;
BOOL                       fMoreAppropriate;
LONG                       lCount;

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

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

if (SUCCEEDED(hr))
   // Get the phrase's text.
   hr = cpPhrase->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &pwszText;, NULL);

if (SUCCEEDED(hr))
   // Check the phrase's text... Assume that
   // the phrase isn't a correct recognition.

   // Get the top MY_MAX_ALTERNATES alternates
   // to the entire recognized phrase.
   hr = cpRecoResult->GetAlternates(pPhrase->Rule.ulFirstElement,

if (SUCCEEDED(hr))
   // Check each alternate in order of highest likelihood.
   for (int i = 0; i < lCount; i++)
      hr = pcpPhraseAlt[i]->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &pwszAlternate;, NULL);

      if (SUCCEEDED(hr))
         // ... Check if this alternate is more appropriate ...

         // If it is more appropriate, then commit the alternate--
         if (fMoreAppropriate)
            hr = pcpPhraseAlt[i]->Commit();

         if (SUCCEEDED(hr))
            // Release system resources:
            if (pwszAlternate) ::CoTaskMemFree(pwszAlternate);
            if (pwszText) ::CoTaskMemFree(pwszText);

// Free the initial phrase object.
if (pPhrase) ::CoTaskMemFree(pPhrase);