Кортана не подбирает параметры команды

Я работаю над размещенным веб-приложением Windows 10 UWP и пытаюсь добавить поддержку Cortana с помощью файла VCD. У меня есть vcd-файл, метатег и js-файл для обработки голосовых команд, но когда я собираю и запускаю приложение, Cortana не получает параметр команды.

Образец файла vcd.xml

<?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>

Когда я говорю Кортане "VoiceDemo search foo". Кортана возвращается с

Поиск "..." с VoiceDemo

В коде javascript я передаю объект voiceCommand, но для свойства result установлено значение "Search...". Я что-то упустил с файлом vcd.xml?

Javascript код

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");
}

Что показывает Кортана:

Кортана снимок экрана

2 ответа

Я столкнулся с этим вопросом сам этим утром. Для меня это было просто отсутствие интернет-соединения. Без интернета я получал "...". Убедившись, что интернет подключен, я получил правильно произносимую поисковую фразу.

Основываясь на информации в наших комментариях, наиболее вероятная проблема связана с вашим новым кодом команды в файле vcd. Новая команда может конфликтовать со старой, поэтому будет работать с этой новой командой по-старому.

Я добавил новую голосовую команду, например:

<?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>

И я справляюсь с новым Open команда в файле js веб-приложения, например:

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";
    }
}

Я обновляю свой пример на GitHub, чтобы вы могли проверить его, я специально не обрабатывал новую команду "Найти", когда вы просите Кортану "voice demo find abc", он откроет приложение VoiceDemo и покажет "еще" в его содержании.

Другие вопросы по тегам