Поділитися через


SpeechRecognitionEngine.UpdateRecognizerSetting Method

Definition

Updates the value of a setting for the recognizer.

Overloads

UpdateRecognizerSetting(String, Int32)

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

UpdateRecognizerSetting(String, String)

Updates the specified speech recognition engine setting with the specified string value.

Remarks

Recognizer settings can contain string, 64-bit integer, or memory address data. The following table describes the settings that are defined for a Microsoft Speech API (SAPI)-compliant recognizer. The following settings must have the same range for each recognizer that supports the setting. A SAPI-compliant recognizer is not required to support these settings and can support other settings.

Name Description
ResourceUsage Specifies the recognizer's CPU consumption. The range is from 0 to 100. The default value is 50.
ResponseSpeed Indicates the length of silence at the end of unambiguous input before the speech recognizer completes a recognition operation. The range is from 0 to 10,000 milliseconds (ms). This setting corresponds to the recognizer's EndSilenceTimeout property. Default = 150ms.
ComplexResponseSpeed Indicates the length of silence in milliseconds (ms) at the end of ambiguous input before the speech recognizer completes a recognition operation. The range is from 0 to 10,000ms. This setting corresponds to the recognizer's EndSilenceTimeoutAmbiguous property. Default = 500ms.
AdaptationOn Indicates whether adaptation of the acoustic model is ON (value = 1) or OFF (value = 0). The default value is 1 (ON).
PersistedBackgroundAdaptation Indicates whether background adaptation is ON (value = 1) or OFF (value = 0), and persists the setting in the registry. The default value is 1 (ON).

To return one of the recognizer's settings, use the QueryRecognizerSetting method.

With the exception of PersistedBackgroundAdaptation, 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.

You can modify how the speech recognition responds to non-speech input using the BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, and EndSilenceTimeoutAmbiguous properties.

UpdateRecognizerSetting(String, Int32)

Source:
SpeechRecognitionEngine.cs
Source:
SpeechRecognitionEngine.cs
Source:
SpeechRecognitionEngine.cs

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

public:
 void UpdateRecognizerSetting(System::String ^ settingName, int updatedValue);
public void UpdateRecognizerSetting (string settingName, int updatedValue);
member this.UpdateRecognizerSetting : string * int -> unit
Public Sub UpdateRecognizerSetting (settingName As String, updatedValue As Integer)

Parameters

settingName
String

The name of the setting to update.

updatedValue
Int32

The new value for the setting.

Exceptions

settingName is null.

settingName is the empty string ("").

The recognizer does not have a setting by that name.

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

Remarks

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.

See also

Applies to

UpdateRecognizerSetting(String, String)

Source:
SpeechRecognitionEngine.cs
Source:
SpeechRecognitionEngine.cs
Source:
SpeechRecognitionEngine.cs

Updates the specified speech recognition engine setting with the specified string value.

public:
 void UpdateRecognizerSetting(System::String ^ settingName, System::String ^ updatedValue);
public void UpdateRecognizerSetting (string settingName, string updatedValue);
member this.UpdateRecognizerSetting : string * string -> unit
Public Sub UpdateRecognizerSetting (settingName As String, updatedValue As String)

Parameters

settingName
String

The name of the setting to update.

updatedValue
String

The new value for the setting.

Exceptions

settingName is null.

settingName is the empty string ("").

The recognizer does not have a setting by that name.

Remarks

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.

See also

Applies to