运行 带有一个参数的 Cortana 的 UWP 应用程序
Run UWP app with Cortana with one parameter
我正在尝试在命令行样式中使用 Cortana/Start:
(按开始写:)
MyApp parameter_I_want_to_pass_to_my_app
这是我的 voiceCommands.xml
文件的一部分:
<Command Name="mycommand">
<Example> something </Example>
<ListenFor RequireAppName="BeforePhrase">{parameter}</ListenFor>
<Feedback> Doing something with: {parameter} </Feedback>
<Navigate />
</Command>
parameter
在同一个 xml 中指定:
<PhraseTopic Label="parameter" />
它不起作用。 Here 在文档中有一些关于 PhaseTopic
的限制,并在阶段开始时使用它。但是这些限制仅在 RequireAppName
是 "AfterPhrase"
或 "ExplicitlySpecified"
时才存在(在我的样本中有 BeforePhrase
)
添加一个词后一切正常:
<ListenFor RequireAppName="BeforePhrase">word {parameter}</ListenFor>
和"command"改为:
MyApp word parameter_I_want_to_pass_to_my_app
这是毫无意义的话...
所以问题是如何使用 Cortana 向我的应用程序传递参数?
___EDIT___
正如 Jay Zuo - MSFT 所示 - 可以仅使用应用程序名称将参数传递给应用程序。
问题介于 Cortana 和应用程序调试之间。每次构建应用程序后都不会刷新命令列表。
Uninstalling app, clearing Cortana history, restarting computer and installing app again
helped.
我从您的代码中可以看出的唯一问题是您在 PhraseTopic
中使用了错误的 Label。在您的 Command
中,您正在使用 "parameter" 作为您的 标签 。所以在 PhraseTopic
中 Label
也应该是 "parameter" 而不是 "destination".
<PhraseTopic Label="parameter" />
在此之后,您的命令应该可以工作了。以 Cortana voice command sample 为例,一旦我们将 Command
和 PhraseTopic
添加到其 VCD 文件中,我们就可以使用 Cortana 启动应用程序,方法如下:
"adventure works this is a test"
您可能需要检查 AppName 是否被正确识别。例如,在这里,一个有效的语音命令必须以 "adventure works" 开头。如果你的说话被识别为"AdventureWorks this is a test"那么它就不会工作。
您可能已经知道,测试您注册的语音命令的一种简单方法是在 Cortana 搜索框中键入命令,如下所示:
如上输入,应该没有问题。
我正在尝试在命令行样式中使用 Cortana/Start:
(按开始写:)
MyApp parameter_I_want_to_pass_to_my_app
这是我的 voiceCommands.xml
文件的一部分:
<Command Name="mycommand">
<Example> something </Example>
<ListenFor RequireAppName="BeforePhrase">{parameter}</ListenFor>
<Feedback> Doing something with: {parameter} </Feedback>
<Navigate />
</Command>
parameter
在同一个 xml 中指定:
<PhraseTopic Label="parameter" />
它不起作用。 Here 在文档中有一些关于 PhaseTopic
的限制,并在阶段开始时使用它。但是这些限制仅在 RequireAppName
是 "AfterPhrase"
或 "ExplicitlySpecified"
时才存在(在我的样本中有 BeforePhrase
)
添加一个词后一切正常:
<ListenFor RequireAppName="BeforePhrase">word {parameter}</ListenFor>
和"command"改为:
MyApp word parameter_I_want_to_pass_to_my_app
这是毫无意义的话...
所以问题是如何使用 Cortana 向我的应用程序传递参数?
___EDIT___
正如 Jay Zuo - MSFT 所示 - 可以仅使用应用程序名称将参数传递给应用程序。 问题介于 Cortana 和应用程序调试之间。每次构建应用程序后都不会刷新命令列表。
Uninstalling app, clearing Cortana history, restarting computer and installing app again helped.
我从您的代码中可以看出的唯一问题是您在 PhraseTopic
中使用了错误的 Label。在您的 Command
中,您正在使用 "parameter" 作为您的 标签 。所以在 PhraseTopic
中 Label
也应该是 "parameter" 而不是 "destination".
<PhraseTopic Label="parameter" />
在此之后,您的命令应该可以工作了。以 Cortana voice command sample 为例,一旦我们将 Command
和 PhraseTopic
添加到其 VCD 文件中,我们就可以使用 Cortana 启动应用程序,方法如下:
"adventure works this is a test"
您可能需要检查 AppName 是否被正确识别。例如,在这里,一个有效的语音命令必须以 "adventure works" 开头。如果你的说话被识别为"AdventureWorks this is a test"那么它就不会工作。
您可能已经知道,测试您注册的语音命令的一种简单方法是在 Cortana 搜索框中键入命令,如下所示:
如上输入,应该没有问题。