Export (0) Print
Expand All

Grammar::Priority Property

Gets or sets the priority value of a Grammar object.

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

public:
property int Priority {
	int get ();
	void set (int value);
}

Property Value

Type: System::Int32
The Priority property returns an integer value that represents the relative priority of a specific Grammar. The range is from -128 to 127 inclusive. The default is 0.

The Priority property is used to select a grammar when more than one grammar will produce an identical recognition result. If a speech recognizer has more than one speech recognition grammar loaded and enabled that match the input, and the match is the best result from the recognizer, then the recognizer uses the grammar that has the highest Priority. If the grammars that produce the identical recognition result also have the same Priority value, then the grammar that the recognizer uses is undefined.

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

.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