ISpPhraseAlt::Commit

Microsoft Speech SDK

The Microsoft.com Speech website Microsoft Speech SDK SAPI 5.1

ISpPhraseAlt::Commit

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

HRESULT  Commit  ( void );

Parameters

None

Return values

Value Description
S_OK Function completed successfully.
SPERR_NOT_FOUND The alternate object is not related to a valid parent phrase object.

Remarks

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).

Example

The following code snippet illustrates the use ISpPhraseAlt::Commit to 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);