Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Create Alternative User Commands (Microsoft.Speech)

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 (Microsoft.Speech) 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 (Microsoft.Speech) 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 (Microsoft.Speech), 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 (Microsoft.Speech)

one-of Element (Microsoft.Speech)