【问题标题】:Cortana not picking up the command parametersCortana 没有获取命令参数
【发布时间】:2016-01-29 22:20:14
【问题描述】:

我正在开发 Windows 10 UWP 托管 Web 应用程序,并且正在尝试使用 vcd 文件添加 Cortana 支持。我有 vcd 文件、meta 标签和一个 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>

当我对 Cortana 说“VoiceDemo search foo”时。 Cortana 回来了

使用 VoiceDemo 搜索“...”

在 javascript 代码中,我获取了传入的 voiceCommand 对象,但结果属性设置为“搜索 ...”。我是否遗漏了 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");
}

Cortana 显示的内容:

【问题讨论】:

  • 测试了你的vcd.xml文件,在我这边运行良好,可能是你的js代码有问题。
  • 我更新了我的帖子以包含 js 代码。还添加了 Cortana 屏幕截图,以显示文本在到达 js 之前显示为“...”或 null。在您进行测试时,您是否使用了托管网络应用程序?
  • 不,我没有在托管网络应用程序中测试它。但是我刚刚创建了一个名为“TestVoiceDemo”的空网络应用程序和一个名为“VocieDemo”的托管网络应用程序,并且我上传了我的测试here in GitHub,我仍然无法重现您的问题,您可以测试我的代码,请记住测试时编辑 VoiceDemo 项目清单中的“起始页”和内容 URI。
  • 已设置起始页和内容 URI。 Cortana 可以工作,但不会获取 vcd.xml 文件的更改。即使应用程序被卸载。使用您创建的示例,添加一个新命令并查看 Cortana 是否识别它或将其视为现有命令的参数。
  • “将其视为现有参数的参数”是什么意思?我刚刚添加了一个新命令,并首先更新了我的 web 应用程序来监听这个新命令,一切都在我身边顺利进行。这可能是操作系统版本的问题吗?我的版本是 1511,os build 10586.63。

标签: windows-10 win-universal-app cortana hosted-app


【解决方案1】:

我今天早上自己遇到了这个问题。对我来说,这只是缺乏互联网连接。没有互联网,我得到“......”。确保互联网已连接后,我得到了正确的搜索词组。

【讨论】:

  • 此外,当我键入 cortana(有或没有互联网)时,我遇到了这个问题。连接时通过麦克风说出的话会产生真实值,没有...
【解决方案2】:

根据我们 cmets 中的信息,最可能的问题是您在 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>

我在 web 应用程序的 js 文件中处理新的Open 命令,如下所示:

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

我更新了我的sample on GitHub,你可以测试一下,我没有专门处理新命令“Find”,当你要求Cortana“voice demo find abc”时,它会打开VoiceDemo应用,并显示其内容中的“其他”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    相关资源
    最近更新 更多