Compartilhar via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

SpeechRecognitionEngine.MaxAlternates Property

Gets or sets the maximum number of alternate recognition results that the SpeechRecognitionEngine returns for each recognition operation.

Namespace:  Microsoft.Speech.Recognition
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

'Declaration
Public Property MaxAlternates As Integer
    Get
    Set
'Usage
Dim instance As SpeechRecognitionEngine
Dim value As Integer

value = instance.MaxAlternates

instance.MaxAlternates = value
public int MaxAlternates { get; set; }

Property Value

Type: System.Int32
The number of alternate results to return.

Exceptions

Exception Condition
ArgumentOutOfRangeException

MaxAlternates is set to a value less than 0.

Remarks

The Alternates property of the RecognitionResult class contains the collection of RecognizedPhrase objects that represent possible interpretations of the input.

The default value for MaxAlternates is 10.

Examples

The example below shows a handler for a TextChanged() event that allows end user to update the value of MaxAlternates.

private void _maxAltsInput_TextChanged(object sender, EventArgs e) 
{
  int newMax;
  newMax = _recognizer.MaxAlternates;
  try 
  {
    newMax = int.Parse(_maxAltsInput.Text, System.Globalization.NumberStyles.Integer);
  }
  catch (Exception exception) 
  {
    MessageBox.Show(string.Format(
         "Invalid Input:   {0}\n Error Message:   {1}",
        _maxAltsInput.Text, exception.Message));
  }
  _recognizer.MaxAlternates = newMax;
  _maxAltsInput.Text = _recognizer.MaxAlternates.ToString();
}

See Also

Reference

SpeechRecognitionEngine Class

SpeechRecognitionEngine Members

Microsoft.Speech.Recognition Namespace

SpeechRecognitionEngine

Alternates