Compartir a través de


Note

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

SpeechRecognitionEngine.UpdateRecognizerSetting Method (String, Int32)

Updates the specified setting for the SpeechRecognitionEngine with the specified integer value.

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

Syntax

'Declaration
Public Sub UpdateRecognizerSetting ( _
    settingName As String, _
    updatedValue As Integer _
)
'Usage
Dim instance As SpeechRecognitionEngine
Dim settingName As String
Dim updatedValue As Integer

instance.UpdateRecognizerSetting(settingName, _
    updatedValue)
public void UpdateRecognizerSetting(
    string settingName,
    int updatedValue
)

Parameters

  • settingName
    Type: System.String
    The name of the speech recognition engine setting.
  • updatedValue
    Type: System.Int32
    The updated value of the speech recognition engine setting.

Exceptions

Exception Condition
ArgumentNullException

settingName is a null reference (Nothing in Visual Basic).

ArgumentException

settingName is the empty string ("").

KeyNotFoundException

The recognizer does not have a setting by that name.

Remarks

Property values set using the UpdateRecognizerSetting() methods remain in effect only for the current instance of SpeechRecognitionEngine, after which they revert to their default settings.

To return one of the recognizer's settings, use the QueryRecognizerSetting method. See UpdateRecognizerSetting for descriptions of supported settings.

Examples

The following example is part of a console application that outputs the values for a number of the settings defined for the recognizer that supports the en-US locale. The example updates the confidence level settings, and then queries the recognizer to check the updated values. The example generates the following output.

Settings for recognizer MS-1033-80-DESK:

  ResourceUsage                  is not supported by this recognizer.
  HighConfidenceThreshold        = 80
  NormalConfidenceThreshold      = 50
  LowConfidenceThreshold         = 20
  ResponseSpeed                  = 150
  ComplexResponseSpeed           = 500


Updated settings:

  ResourceUsage                  is not supported by this recognizer.
  HighConfidenceThreshold        = 60
  NormalConfidenceThreshold      = 40
  LowConfidenceThreshold         = 15
  ResponseSpeed                  = 150
  ComplexResponseSpeed           = 500


Press any key to exit...
using System;
using System.Globalization;
using Microsoft.Speech.Recognition;

namespace RecognizerSettings
{
  class Program
  {
    static readonly string[] settings = new string[] {
      "ResourceUsage",
      "HighConfidenceThreshold",
      "NormalConfidenceThreshold",
      "LowConfidenceThreshold",
      "ResponseSpeed",
      "ComplexResponseSpeed"
    };

    static void Main(string[] args)
    {
      using (SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
      {
        Console.WriteLine("Settings for recognizer {0}:",
          recognizer.RecognizerInfo.Name);
        Console.WriteLine();

        // List the current settings.
        ListSettings(recognizer);

        // Change some of the settings.
        recognizer.UpdateRecognizerSetting("HighConfidenceThreshold", 60);
        recognizer.UpdateRecognizerSetting("NormalConfidenceThreshold", 40);
        recognizer.UpdateRecognizerSetting("LowConfidenceThreshold", 15);

        Console.WriteLine("Updated settings:");
        Console.WriteLine();

        // List the updated settings.
        ListSettings(recognizer);
      }

      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }

    private static void ListSettings(SpeechRecognitionEngine recognizer)
    {
      foreach (string setting in settings)
      {
        try
        {
          object value = recognizer.QueryRecognizerSetting(setting);
          Console.WriteLine("  {0,-30} = {1}", setting, value);
        }
        catch
        {
          Console.WriteLine("  {0,-30} is not supported by this recognizer.",
            setting);
        }
      }
      Console.WriteLine();
    }
  }
}

See Also

Reference

SpeechRecognitionEngine Class

SpeechRecognitionEngine Members

UpdateRecognizerSetting Overload

Microsoft.Speech.Recognition Namespace