SpeechRecoContext CmdMaxAlternates Property

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoContext

CmdMaxAlternates Property


The CmdMaxAlternates property specifies the maximum number of alternates that will be generated for command and control grammars.

By default, the maximum alternates value is zero, so an application must call this method before attempting to retrieve or depend on alternates for command and control. Not all speech recognition engines support command and control or proprietary grammar alternates. If the particular engine does not support alternates, this method will indicate it has succeeded but the number of alternates returned will always be zero.

CmdMaxAlternates has no effect on dictation alternates. See ISpeechRecoResult.Alternates for information regarding dictation alternates.


Syntax

Set: SpeechRecoContext.CmdMaxAlternates = Long
Get: Long = SpeechRecoContext.CmdMaxAlternates

Parts

SpeechRecoContext
The owning object.
Long
Set: A Long variable setting the maximum number of alternates.
Get: A Long variable retrieving the maximum number of alternates.

Remarks

The current version of the Microsoft speech recognition engine supplied with SAPI 5 does not support command and control alternates. However, other manufacturer's engines may.

Example

The following snippet demonstrates retrieving the current number of alternates. However, because not all engines support the alternates feature, a test is performed beforehand. If the attribute does not exist, the application receives a run-time error of SPERR_NOT_FOUND. The On Error statement provides a graceful handling in that case. If the attribute does exist, no error will occur and cfgAttribute will be valid, even if only as Empty.

The samples assumes a valid RecoResult.

Dim objToken As Object
Set objToken = RecoResult.RecoContext.Recognizer.Recognizer

On Error GoTo ErrorHandler

Dim cfgAttribute As String
cfgAttribute = objToken.GetAttribute("CGFAlternates")

Dim numAlternates As Long
numAlternates = RecoResult.RecoContext.CmdMaxAlternates 
Exit Sub

ErrorHandler:
	'Error handling code here
	Debug.Print Err.Number
End Sub