I'm working on Windows 10 UWP Hosted Web application and I'm trying to add Cortana support with a vcd file. I have the vcd file, meta tag, and a js file to handle the voice commands, but when I build and run the app, Cortana doesn't pick up the command parameter.
Sample vcd.xml file
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="VoiceDemoCommandSet_en-us">
<AppName>VoiceDemo</AppName>
<Example>VoiceDemo search for foo</Example>
<Command Name="Search">
<Example>search {message} using VoiceDemo</Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase">Search {searchTerm}</ListenFor>
<Feedback>Searching for "{searchTerm}" with VoiceDemo</Feedback>
<Navigate Target="/home/about"/>
</Command>
<PhraseTopic Label="searchTerm" Scenario="Natural Language"/>
</CommandSet>
</VoiceCommands>
When I say to Cortana "VoiceDemo search foo". Cortana comes back with
Searching for "..." with VoiceDemo
In the javascript code, I get the voiceCommand object passed in, but the result property is set to "Search ...". Am I missing something with the vcd.xml file?
Javascript code
if (typeof Windows !== 'undefined' &&
typeof Windows.UI !== 'undefined' &&
typeof Windows.ApplicationModel !== 'undefined') {
// Subscribe to the Windows Activation Event
Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function (args) {
var activation = Windows.ApplicationModel.Activation;
// Check to see if the app was activated by a voice command
if (args.kind === activation.ActivationKind.voiceCommand) {
var speechRecognitionResult = args.result;
var textSpoken = speechRecognitionResult.text;
// Determine the command type {search} defined in vcd
if (speechRecognitionResult.rulePath[0] === "Search") {
console.log("speechRecognitionResult: " + speechRecognitionResult);
console.log("textSpoken: " + textSpoken);
// Build rest of search string here
// Then invoke search
}
else {
console.log("No valid command specified");
}
}
});
} else {
console.log("Windows namespace is unavaiable");
}
What Cortana displays: