我正在努力让Cortana在我的托管网络应用程序中工作。但是,我陷入了一个问题,我没有得到用户与Cortana谈过的文本。以下是应该发生的事情:
如果用户说“ChangeWindows show build 14393”,应该打开应用程序并导航到地址“/ build / 14393”。但是,我不知道如何获得这个数字。这是我现在的代码:
vcd.xml
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="ChangeWindowsPreview">
<CommandPrefix>ChangeWindows</CommandPrefix>
<Example>Navigate to a changelog, milestone or build</Example>
<Command Name="OpenBuild">
<Example>Show build 14393</Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase">Show [build] {build}</ListenFor>
<Feedback>Opening build {build} with ChangeWindows</Feedback>
<Navigate />
</Command>
<Command Name="OpenNext">
<Example>Show the next major release</Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase">Show [the] next [major] [feature] [release]</ListenFor>
<Feedback>Opening vNext with ChangeWindows</Feedback>
<Navigate />
</Command>
<PhraseTopic Label="build" Scenario="Dictation"></PhraseTopic>
</CommandSet>
</VoiceCommands>
对于我的JS,我有:
<script type="text/javascript">
if ( typeof Windows !== 'undefined' ) {
var activation = Windows.ApplicationModel.Activation;
Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function (args) {
if ( args.kind === activation.ActivationKind.voiceCommand ) {
var speechRecognitionResult = args.result;
if ( speechRecognitionResult.rulePath[0] === "OpenBuild" ) {
console.log( "Opening this build from Cortana: " + speechRecognitionResult.text );
window.location.replace( "/build/" + speechRecognitionResult.text );
}
if ( speechRecognitionResult.rulePath[0] === "OpenNext" ) {
console.log( "Opening next feature release with Cortana" );
window.location.replace( "/build/next" );
}
}
})
}
</script>
所以,显然,'speechRecognitionResult.text'不是我在这里寻找的。我希望有人知道应该在那里获得{build}。