The structure of the VCD file has a root VoiceCommands
element that contains zero or more CommandSet
elements. See Listing 23.14.
The CommandSet
element represents a group of commands that are activated when the value of the CommandPrefix
element is spoken by the user. This allows you to group multiple phrases together.
The Example
element determines the text that is displayed on the speech recognition dialog, which is displayed when the user taps and holds the phone’s Windows button.
Each CommandSet
is required to have at least one Command
element, and each Command
element is required to have at least one and a maximum of 10 ListenFor
elements. ListenFor
elements define the speech that activates a particular command. Square brackets within the ListenFor
element indicate that the text is optional, whereas curly braces refer to another PhraseList
within the document.
Note
A CommandSet
cannot contain more than 25 command elements and a PhraseList
element cannot contain more than 500 Item elements.
In Listing 23.14 the ShowWeather
command is activated when the user says any of the following phrases:
Weather for Zurich Switzerland
Weather Zurich Switzerland
Weather for London England
Weather London England
Although commands themselves cannot be added programmatically to a CommandSet
at run-time, the contents of a PhraseList
can be replaced programmatically. You see how to achieve this later in the chapter.
The Feedback
element defines the response to the user when the command is recognized. By using curly brace notation, such as {City}, the recognized phrase list value is placed into the response.
Note
A PhraseList
reference in a Feedback
element must match a corresponding reference in a ListenFor
element in the same command.
When the voice command system recognizes a command, your app is launched and the URL specified by the Target
attribute of the Navigate
element is navigated to.
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">
<CommandSet xml:lang="en-us" Name="WeatherCommandSet">
<CommandPrefix>Weather</CommandPrefix>
<Example>Weather for Zurich Switzerland</Example>
<Command Name="ShowWeather">
<Example>Weather for Zurich Switzerland</Example>
<ListenFor>[For] {City}</ListenFor>
<Feedback>Showing weather for {City}</Feedback>
<Navigate Target="Speech/VoiceCommands/VoiceCommandView.xaml"/>
</Command>
<PhraseList Label="City">
<Item>Zurich Switzerland</Item>
<Item>London England</Item>
<!-- This phrase list is replaced programmatically
in the VoiceCommandViewModel class. -->
</PhraseList>
</CommandSet>
<!-- Other CommandSets for other languages -->
</VoiceCommands>
A wildcard token that recognizes any speech can be placed within the ListenFor
element, as shown:
<ListenFor>Weather [for] {*}</ListenFor>
This allows you to define commands that register a partial match for a phrase.
18.119.106.237