我正在开发 Windows 10 UWP 托管 Web 应用程序,并且正在尝试使用 vcd 文件添加 Cortana 支持。我有 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>
当我对 Cortana 说“VoiceDemo 搜索 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 显示的内容: