Compartilhar via


Grammar.Weight Property

Definition

Gets or sets the weight value of a Grammar object.

public:
 property float Weight { float get(); void set(float value); };
public float Weight { get; set; }
member this.Weight : single with get, set
Public Property Weight As Single

Property Value

The Weight property returns a floating point value indicating the relative weight that a recognition engine instance should assign to the grammar when processing speech input. The range is from 0.0 to 1.0 inclusive. The default is 1.0.

Examples

The following example creates two Grammar objects, one for digits and one for fractions. The Grammar objects are assigned names and relative weights and priorities, and loaded by an in-process speech recognizer. The CreateDigitsGrammar, CreateFractionsGrammar, and recognizer_SpeechRecognized methods are not shown here.

// Create a Grammar for recognizing numeric digits.  
Grammar digitsGrammar = CreateDigitsGrammar();  
digitsGrammar.Name = "Digits Grammar";  
digitsGrammar.Priority = 2;  
digitsGrammar.Weight = 0.6f;  

// Create a Grammar for recognizing fractions.  
Grammar fractionsGrammar = CreateFractionsGrammar();  
fractionsGrammar.Name = "Fractions Grammar";  
fractionsGrammar.Priority = 1;  
fractionsGrammar.Weight = 1f;  

// Create an in-process speech recognizer.  
SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();  

recognizer.SpeechRecognized +=  
  new EventHandler<SpeechRecognizedEventArgs>(  
    recognizer_SpeechRecognized);  

// Load the digits and fractions Grammar objects.  
recognizer.LoadGrammar(digitsGrammar);  
recognizer.LoadGrammar(fractionsGrammar);  

// Start recognition.  
recognizer.SetInputToDefaultAudioDevice();  
recognizer.RecognizeAsync(RecognizeMode.Multiple);  

Remarks

Because of the complexity of a recognition engine's use of Weight, its effect on a particular grammar's performance is not as directly predictable as that of Priority.

Speech recognition is a weighted system. It evaluates all possible recognition paths based on a combination of the weight of the grammar, the weights defined for alternatives within the grammar, and the probabilities defined by speech models. The speech recognition engine uses the combination of these weights and probabilities to rank potential alternative recognitions. Grammars with higher weights will contribute more to the ranking of recognition alternatives than grammars with lower weights.

The effect of the Weight property on a speech recognizer is dependent on the implementation of the recognizer. Although the Weight property can be used to tune the accuracy of speech recognition for an application, it should be used only after controlled diagnostic study of a particular recognition environment and with full information about the recognition engine under use.

Applies to

See also