Export (0) Print
Expand All

SpeechRecognitionEngine.UpdateRecognizerSetting Method (String, Int32)

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

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

public void UpdateRecognizerSetting(
	string settingName,
	int updatedValue
)

Parameters

settingName
Type: System.String

The name of the setting to update.

updatedValue
Type: System.Int32

The new value for the setting.

ExceptionCondition
ArgumentNullException

settingName is null.

ArgumentException

settingName is the empty string ("").

KeyNotFoundException

The recognizer does not have a setting by that name.

With the exception of PersistedBackgroundAdaptation, property values set using the UpdateRecognizerSetting method remain in effect only for the current instance of SpeechRecognitionEngine, after which they revert to their default settings. See UpdateRecognizerSetting for descriptions of supported settings.

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.
  ResponseSpeed                  = 150
  ComplexResponseSpeed           = 500
  AdaptationOn                   = 1
  PersistedBackgroundAdaptation  = 1

Updated settings:

  ResourceUsage                  is not supported by this recognizer.
  ResponseSpeed                  = 200
  ComplexResponseSpeed           = 300
  AdaptationOn                   = 0
  PersistedBackgroundAdaptation  = 0

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

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

    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("ResponseSpeed", 200);
        recognizer.UpdateRecognizerSetting("ComplexResponseSpeed", 300);
        recognizer.UpdateRecognizerSetting("AdaptationOn", 1);
        recognizer.UpdateRecognizerSetting("PersistedBackgroundAdaptation", 0);

        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();
    }
  }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft