ISpeechRecoResult Alternates Method

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoResult

Alternates Method

The Alternates method returns a list of alternate words.

Many recognitions, successful or not, frequently return several words or phrases that closely match the spoken sequence. The one most nearly matching the sequence with a high confidence level is returned as a successful recognition. The other words and phrases are returned as alternates that are available for examination.


ISpeechRecoResult.Alternates(
     RequestCount As Long,
     [StartElement As Long = 0],
     [Elements As Long = -1]
) As ISpeechPhraseAlternates

Parameters

RequestCount
Specifies the maximum number of alternates to retrieve, which must be greater than zero. Any number of alternates may be chosen and will be returned in descending order of confidence. That is, the first alternate returned has the highest confidence and will most likely be the word or phrase chosen by the successful recognition. The second alternate returned will be the next most likely choice, and the last alternate returned the least likely match.
StartElement
[Optional] Specifies which element to use as a starting point. If omitted, zero is used and indicates the first alternate as the starting point. Because it is zero based, the second element would be one.
Elements
[Optional] Specifies the number of elements to retrieve. Default is -1, which specifies all alternate elements are retrieved.

Return Value

The Alternates method returns an ISpeechPhraseAlternates variable.

Remarks

ISpeechRecoResult.Alternates applies only to dictation grammar. Command and control alternates are handled separately and independently. See ISpeechRecoContext.CmdMaxAlternates for command and control alternates.

Example

The following example returns the 30 most likely matches for a recognition. It assumes a successful recognition in RecoResult. The example also only uses one parameter, the number of alternates to return; the other parameters are assigned by default and return all the available words and phrases.

Dim phraseAlternate As ISpeechPhraseAlternates
Dim i As Long
Dim theString As String
    
Set phraseAlternate = RecoResult.Alternates(30)
For i = 0 To phraseAlternate.Count - 1
	theString = phraseAlternate.Item(i).GetText
	TextField.Text = TextField.Text + "Alternates #" + str(i) + ": " + theString + vbCrLf
Next i

If the recognition was "we the people," then the first six alternates might look like the following. Notice that the first alternate is the recognized word or phrase.

Alternates #0: we the people
Alternates #1: we have people
Alternates #2: we people
Alternates #3: we do people
Alternates #4: we had people
Alternates #5: we can people