Building Grammars with the Grammar Editor
If you download the code that accompanies this article, you can access the Grammar Explorer by opening the project file and drilling down to the Orders.grxml
file located in the Grammars
subdirectory. From there, you should see a list of rules associated with this grammar file. Double-click the OrderTypeRule item, and the Grammar Editor opens (see Figure 1
). From here you can build, edit, and test grammar files.
|Figure 1. The Grammar Editor: The figure shows the Grammar Editor opened on the OrderTypeRule item.|
You build grammars by dragging controls from the toolbox on the left side of the Grammar Editor onto the drawing design surface. Table 1 identifies the grammar controls available in the grammar toolbox. The OrderTypeRule in Figure 1
uses a group control to relate three different rule references. The rule enables the OrderTypeQA control to identify exactly what order type the caller wishes to hear. It's referenced by the OrderTypeQA control in the Default.aspx
page through the grammar collection. You can see this reference if you view the HTML for Default.aspx
. The reference should appear as follows:
Table 1: The table lists the grammar controls available through the grammar toolbox in Visual Studio.
|Phrase||Represents the actual phrase spoken by the user.|
|List||Used to contain multiple phrase elements that all relate to the same thing. For example, a "yes" response could be spoken as "Yes", "Yeah", or "OK".|
|RuleRef||Used to reference other rules through the URI property. This is useful when you want to reuse the logic in existing rules.|
|Group||Used to group related elements such as a List, Phrase, or RuleRef.|
|Wildcard||Used to specify which words in a phrase can be ignored.|
|Halt||Used to stop the recognition path.|
|Skip||Used to indicate that a recognition path is optional.|
|Script Tag||Used to compare the value of the Semantic Markup Language (SML) tag with the matching values.|
contains a list control that identifies several phrases a caller might say at the beginning of a response. For instance, callers are prompted for the order type with the following text to speech: "Do you need to hear about pending or shipped orders?" Callers might respond in a variety of ways: They might say, "Give me all shipped orders," or "I want the pending ones please." Either response is fine, because you can use PreambleRuleRef
rules to represent the extra words people use in natural speech. In the example phrases listed above, "Give me all" and "I want the" represent the preamble phrases, while "orders" and "ones please" represent postamble phrases. The meat of the response is the word "shipped" or "pending" that represents which order type the caller wants to retrieve. The OrderTypeRuleRef captures this essential part of the caller's response.
The Grammar Editor lets you to test grammars by typing a phrase into the Recognition String text box. After typing a phrase, click the Check button, and watch the Output window for results. If the grammar was located and validated successfully, then you should see an XML based string that represents the SML. So, if you were to type in the phrase, "Give me all shipped orders," the output would appear as shown in Figure 2
|Figure 2. Testing Grammars: When testing grammars, the test results appear in the Output window as an XML string that represents the SML.|
The SML result returned from the Speech Recognizer is used to value semantic items. These semantic items are declared in the Default,aspx
page as part of the SemanticMap speech control. Each semantic item is used to store some piece of information collected from the caller. For example, the semantic item named siOrderType
stores the value associated with the tag named Type
. This value will be used in the code when populating the DataTableNavigator speech control with customer orders.
You may notice that the SML contains an attribute named confidence
. In Figure 2
this attribute contains a value of 1.00, which indicates 100 percent confidence that the result returned from the speech recognizer is accurate. The confidence score is this high because I typed in the text when testing from the Grammar Editor. If I had used a microphone to speak the order type, the confidence score would have been less than 100%. Exactly how much less that value will be depends on the quality of the microphone and the speaking tone and rate used by the caller.