1
votes

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:

Cortana screen shot

2
Tested your vcd.xml file, it works fine by my side, it is possible the problem with your js code.Grace Feng
I updated my post to include the js code. Also added Cortana screenshot to show the text being displayed as "..." or null before it even gets to the js. When you tested, did you use a hosted web app?Chris Miller
No, I didn't tested it in a hosted web app. But I just created a empty web app named "TestVoiceDemo", and a hosted web app named "VocieDemo", and I uploaded my test here in GitHub, I still can't reproduce your problem, you can test my code, please remember to edit the "Start page" and Content URIs in the manifest of VoiceDemo project when you test them.Grace Feng
The StartPage and Content URI are set. Cortana works, but does not pick up changes o the vcd.xml file. Even when the app is uninstalled. With the example you created, add a new command and see if Cortana recognizes it or treats it as parameters to the existing one.Chris Miller
What do you mean by "treats it as parameters to the existing one"? I just added a new command, and updated my web app at first to listen for this new command, every thing goes well by my side. Is that possible the problem with os version? My version is 1511, os build 10586.63.Grace Feng

2 Answers

1
votes

I ran into this issue myself this morning. For me, it was simply lack of internet connectivity. Without internet, I was getting "...". After ensuring the internet was connected, I got the properly spoken search phrase.

0
votes

Based on the information in our comments, the most possible problem is with your new command code in the vcd file. The new command may conflict with the old one, so will it deal this new command in the old way.

I added new voice command like this:

<?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 "{searchTerm}" with VoiceDemo</Feedback>
      <Navigate Target="/home/about" />
    </Command>
    <Command Name="Open">
      <Example>open {message} using VoiceDemo</Example>
      <ListenFor RequireAppName="BeforeOrAfterPhrase">Open {openTerm}</ListenFor>
      <Feedback>Opening "{openTerm}" with VoiceDemo</Feedback>
      <Navigate Target="/home/about" />
    </Command>
    <Command Name="Find">
      <Example>find {message} using VoiceDemo</Example>
      <ListenFor RequireAppName="BeforeOrAfterPhrase">Find {openTerm}</ListenFor>
      <Feedback>Finding "{openTerm}" with VoiceDemo</Feedback>
      <Navigate Target="/home/about" />
    </Command>
    <PhraseTopic Label="searchTerm" Scenario="Natural Language" />
    <PhraseTopic Label="openTerm" />
  </CommandSet>
</VoiceCommands>

And I handle the new Open command in the js file of web app like this:

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);
        document.getElementById("txt").innerText = "search";
        // Build rest of search string here
        // Then invoke search
    }
    else if (speechRecognitionResult.rulePath[0] === "Open") {
        console.log("speechRecognitionResult: " + speechRecognitionResult);
        console.log("textSpoken: " + textSpoken);
        document.getElementById("txt").innerText = "open";
    }
    else {
        console.log("No valid command specified");
        document.getElementById("txt").innerText = "else";
    }
}

I update my sample on GitHub, so you can test it, I didn't specially handle the new command "Find", when you ask Cortana to "voice demo find abc", it will open the VoiceDemo app, and show "else" in the its content.