Share via


Use Grammar Elements to Recognize Speech

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Use the elements in Speech Grammar Editor to design grammar rules that define user speech patterns.

Recognizing Words and Phrases

Use a Phrase element to specify the text of a single word, phrase, or complete sentence that the speech recognition engine recognizes. Phrase elements are the building blocks of grammar rules.

The Phrase element represents an item XML markup element in the XML text of a .grxml file.

Note

When entering text values for Phrase elements, enter text without using quotation marks. Text enclosed by quotation marks is not recognized by the speech recognition engine.

The following code example illustrates XML markup using one Phrase element to represent the phrase "good morning."

<rule id="PhraseElement">

<item>good morning</item>

</rule>

The following code example illustrates XML markup using two Phrase elements to represent the phrase "good morning."

<rule id="PhraseElement" scope="private">

<item>good</item>

<item>morning</item>

</rule>

Note

No element in Speech Grammar Editor represents a rule XML markup element. Each window in Rule Editor represents a rule XML markup element.

When the speech recognition engine combines with either of the previous rules to recognize the phrase "good morning," the recognition engine sends the following SML results to an application.

<SML text="good morning" utteranceConfidence="1.000">

good morning

</SML>

Recognizing Choices from a List

Use List elements to specify a set of alternative words or phrases that a user might speak to an application. When a user says one of the words or phrases in the list, the recognition engine recognizes that word or phrase.

When a grammar author drags a List element onto the Rule Editor window, a child Phrase element appears underneath the List element. Although this is the default behavior, List elements can contain any type of child elements, including Group elements and other List elements.

The List element represents a one-of XML markup element in the XML text of a .grxml file.

The following code example illustrates XML markup using a List element in Speech Grammar Editor to enclose a list of flavor choices???chocolate, raspberry, and vanilla. Three Phrase elements specify the flavor choices, using one Phrase element per choice.

<rule id="ListExample" scope="private">

<item>I'd like a</item>

<one-of>

<item>chocolate</item>

<item>raspberry</item>

<item>vanilla</item>

</one-of>

<item>please</item>

</rule>

When the recognition engine combines with this rule to recognize the phrase "I'd like a chocolate please," the recognition engine sends the following SML results to an application.

<SML text="I'd like a chocolate please" utteranceConfidence="1.000">

I'd like a chocolate please

</SML>

Note

All child elements of the containing List element inherit the properties of the parent List element.

Referencing Other Rules

Use the RuleRef element to reference another rule, either from the same grammar file or from an external grammar file. Use RuleRef elements to reuse preexisting component grammars. For example, the Library.grxml file included with every new project contains preexisting rules that return semantic results for common items such as dates, credit card numbers, and telephone numbers. If the user selects a rule in Library.grxml in Grammar Explorer, a description of the rule appears in the Properties pane. Click the browse button on the Description property to display Rule Description Editor, which contains the attributes and values associated with that rule.

Only rules with the Scope property set to Public are available for reference in other grammars. Rules with Scope set to Private are available for reference only within the grammar containing them.

Note

A compiled version of the default Library.grxml file, named Cmnrules.cfg, is installed with Speech Server. If Speech Server is installed to the default location, Cmnrules.cfg is located at %SystemDrive%\Inetpub\wwwroot\aspnet_speech%Version%\client_script\1033

The RuleRef element represents a ruleref XML markup element in the XML text of a .grxml file.

The following code example shows the XML markup representing RuleRef elements that reference two rules, City and Day, in the same grammar file.

<rule id="RuleRefExample" scope="private">

<item>I'm traveling to</item>

<ruleref uri="#City" type="application/srgs+xml"/>

<item>on</item>

<ruleref uri="#Day" type="application/srgs+xml"/>

</rule>

<rule id="City" scope="private">

<one-of>

<item>Chicago</item>

<item>Denver</item>

<item>Seattle</item>

</one-of>

</rule>

<rule id="Day" scope="private">

<one-of>

<item>Saturday</item>

<item>Sunday</item>

<item>Monday</item>

<one-of>

</rule>

When the recognition engine combines with these rules to recognize the phrase "I'm traveling to Seattle on Monday," the recognition engine sends the following SML results to an application.

<SML text="I'm traveling to Seattle on Monday" utteranceConfidence="1.000">

I'm traveling to Seattle on Monday

</SML>

Ignoring Irrelevant Words

Use the Wildcard element to recognize a phrase but ignore irrelevant words. For example, it might be necessary to recognize the phrase "open message." Recognition should not fail if a user says "open my message," "open the message," or "open the message please." Use the Wildcard element to discard unnecessary words.

The Wildcard element represents a ruleref XML markup element with its special attribute set to GARBAGE in the XML text of a .grxml file.

The following code example shows the XML markup representing Wildcard elements that enable the recognition engine to recognize speech if a user says "open my message," "open the message," "open the message please," or any number of other responses.

<rule id="WildcardExample" scope="private">

<item>open</item>

<ruleref special="GARBAGE"/>

<item>message</item>

<ruleref special="GARBAGE"/>

</rule>

When the recognition engine uses this rule to recognize the phrase "open my message please," the recognition engine sends the following SML results to an application.

<SML text="open ... message ..." utteranceConfidence="1.000">

open ... message ...

</SML>

Note

The ellipses are actually part of the SML results. They represent the unnecessary spoken words.

Disabling Recognition

Use the Halt element to disable recognition of any recognition path that contains this element. This element enables grammar authors to isolate particular recognition paths and rules for testing purposes during development. If Speech Grammar Editor activates a recognition path or rule containing the Halt element, recognition fails.

The Halt element represents a ruleref XML markup element with its special attribute set to VOID in the XML text of a .grxml file.

The following XML markup illustrates using a Halt element in Speech Grammar Editor.

<rule id="HaltExample" scope="private">

<ruleref special="VOID"/>

</rule>

Ignoring Recognition

Use the Skip element to treat a recognition path as optional. Using the Skip element on a recognition path has the same effect as specifying the Min Repeatand Max Repeat properties on that path. The Skip element represents a ruleref XML markup element with its special attribute set to null in the XML text of a .grxml file.

The following XML markup illustrates a Skip element within a List element. The Skip element makes the List optional, so the recognition engine recognizes "hello" or "hello Prasanna."

<rule id="SkipExample" scope="public">

<item>hello</item>

<one-of>

<item>

<ruleref special="NULL"/>

</item>

<item>Francisco</item>

<item>Prasanna</item>

</one-of>

</rule>

Adding Semantic Interpretation Information

Use the Script Tag element to associate other rule elements with property values and scripts that manipulate the Semantic Markup Language (SML) text results returned by the recognition engine. The Script Tag element represents a tag XML markup element in the XML text of a .grxml file.

The following XML markup illustrates using a Script Tag element in Speech Grammar Editor.

<rule id="Tickets" scope="private">

<item>one</item>

<tag>$._value = "1"</tag>

</rule>

Use the Group element to specify that a group of elements are related and to assign properties to a group of elements. For example, if a grammar author sets the Max Repeat property on a Group element, the value of that property also applies to the elements contained in the group. The recognition engine recognizes each item in the group.

When a grammar author drags a Group element onto the Rule Editor window, a child Phrase element appears underneath the Group element. Although this action is the default behavior, Group elements might contain any type of child elements, including List elements and other Group elements.

The Group element represents an item XML markup element in the XML text of a .grxml file. In contrast to the Phrase element, which encloses individual words or phrases in separate item XML markup elements, the Group element encloses all elements in the group with a single item XML markup element.

The XML markup example illustrates using a Group element to group a reference to a rule to recognize a digit, and script tags to increment the count of digits and to capture the digits. The Group element has Min Repeat set to zero and Max Repeat set to 3. Consequently, each element in the group inherits those properties. The rule recognizes from zero to three spoken digits and returns in its semantic information the number of digits spoken, the digits, and the spoken representations of the digits.

<rule id="GroupExample" scope="public">

<tag>$.count = 0;</tag>

<tag>$._value = ""</tag>

<item repeat="0-3">

<ruleref uri="Library.grxml#digit" type="application/srgs+xml"/>

<tag>$._value = $._value + $$._value</tag>

<tag>$.count += 1</tag>

</item>

<tag>$._attributes.text = $recognized.text;</tag>

</rule>

When the recognition engine combines with this rule to recognize the phrase "one two," the recognition engine sends the following SML results to an application.

<SML confidence="1.000" text="one two" utteranceConfidence="1.000">

12

<count>2</count>

</SML>

Note

Although there is no specific World Wide Web Consortium Speech Recognition Grammar Specification (W3C SRGS) Version 1.0 element corresponding to a Group element, using this element does not break W3C SRGS compliance.

See Also

Other Resources

Use Speech Grammar Editor to Create Grammars
Use Conversational Grammar Builder to Create Grammars
Use Speech Server Tools to Develop Voice Response Application Components