Dela via


Create Alternative User Commands

You may want your application to accept any of several spoken commands to initiate a single action. Different users may vocalize the same intent using a variety of expressions. In this topic we will use the list of actions and spoken input you created in the Create a List of User Commands topic to create rules that can be matched with multiple input words or phrase. To contain the list of alternative choices, we will use a new element: one-of.

The one-of element is for defining alternative words or phrases, any of which the user can speak to satisfy the rule. See one-of Element for more information. For example, if you want your application to accept both "play" and "start" to initiate playback of a music file, put each word in an item element and enclose the item elements within a one-of element, as shown in the following example:

<grammar version="1.0" xml:lang="en-US" root="rootRule"
 xmlns="http://www.w3.org/2001/06/grammar">

  <rule id="rootRule">
    <one-of>
      <item> play </item>
      <item> start </item>
    </one-of>
  </rule>

</grammar>

This grammar can now be used to recognize the spoken input "play" or "start", either of which will match the rule named rootRule. The application can use the match to initiate playback of a selected audio file.

Continue adding words or phrases to the rule named rootRule that can be used to initiate begin playback of an audio file. Enclose each word or phrase in an item element, and nest it within the one-of element.

See the next topic, Create Variations of User Commands, to learn how to combine multiple rules into a single rule by using the ruleref element to create rule references.

See Also

Concepts

item Element

one-of Element