无法安装 VCD 文件 UWP installCommandDefinitionsFromStorageFileAsync
Cannot install VCD file UWP installCommandDefinitionsFromStorageFileAsync
我将 Cortana 集成到我的应用程序(UWP 和 Winjs)但是当我尝试安装 VCD 文件时出现错误:
Status is 'error', but getResults did not return an error
main.js(代码包装在应用程序的激活处理程序事件上):
wap.current.installedLocation.getFileAsync("Commands.xml").then(function (file) {
return voiceCommandManager.installCommandDefinitionsFromStorageFileAsync(file);
}, function (er) {
console.error('error file Commands.xml', er);
}).then(function () {
var language = window.navigator.userLanguage || window.navigator.language;
var commandSetName = "BibleCommandSet_" + language.toLowerCase();
if (voiceCommandManager.installedCommandDefinitions.hasKey(commandSetName)) {
var vcd = voiceCommandManager.installedCommandDefinitions.lookup(commandSetName);
} else {
console.log('VCD not installed yet?');
}
}, function (ee) {
console.error("installCommandDefinitionsFromStorageFileAsync error", ee);
});
Commands.xml:
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="BibleCommandSet_en-us">
<AppName> Bible </AppName>
<Example> Go to genesis 1,9 </Example>
<Command Name="goToQuote">
<Example> Go to genesis 1,9 </Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}</ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}{number}</ListenFor>
...
<ListenFor RequireAppName="BeforeOrAfterPhrase"> open {book} {number}{number},{number}{number}</ListenFor>
<Feedback> Ok i'm opening {book} </Feedback>
<Navigate/>
</Command>
</CommandSet>
已修复: 在文件的另一行我有另一个命令集,我确实调用了一个短语列表 "book" 但真实姓名是 "libro"
I integrating Cortana to my app(UWP with Winjs) but when i try to install the VCD file i got that error:Status is 'error', but getResults did not return an error
这是因为您的 VCD 文件有问题 - Command.xml
。由于错误是由VCD文件而不是代码本身引起的,所以您没有得到错误的详细信息。
VCD文件中的特殊字符{}包含了Label属性的值,供PhraseList或PhraseTopic引用。在 ListenFor 或 Feedback 元素中使用。 Feedback 元素中的 PhraseList 或 PhraseTopic 引用必须与同一命令中 ListenFor 元素中的相应引用相匹配。
虽然 PhraseList 或 PhraseTopic 是 CommandSet 的 Optional child,但您在 VCD 文件中为 ListenFor 和 Feedback 元素定义了 {book}
和 {name}
,这需要相应的 PhraseList,其 Label 属性的值为 name
/book
.
我根据你更新了VCD文件,现在代码可以运行成功了。
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="BibleCommandSet_en-us">
<AppName> Bible </AppName>
<Example> Go to genesis 1,9 </Example>
<Command Name="goToQuote">
<Example> Go to genesis 1,9 </Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book}</ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}{number}</ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> open {book} {number}{number},{number}{number}</ListenFor>
<Feedback> Ok i'm opening {book} </Feedback>
<Navigate/>
</Command>
<PhraseList Label="book">
<Item>London</Item>
<Item>Las Vegas</Item>
<Item>Melbourne</Item>
<Item>Yosemite National Park</Item>
</PhraseList>
<PhraseList Label="number">
<Item>2</Item>
<Item>3</Item>
<Item>4</Item>
<Item>5</Item>
</PhraseList>
</CommandSet>
</VoiceCommands>
更详细的VCD文件请参考this document。
我将 Cortana 集成到我的应用程序(UWP 和 Winjs)但是当我尝试安装 VCD 文件时出现错误:
Status is 'error', but getResults did not return an error
main.js(代码包装在应用程序的激活处理程序事件上):
wap.current.installedLocation.getFileAsync("Commands.xml").then(function (file) {
return voiceCommandManager.installCommandDefinitionsFromStorageFileAsync(file);
}, function (er) {
console.error('error file Commands.xml', er);
}).then(function () {
var language = window.navigator.userLanguage || window.navigator.language;
var commandSetName = "BibleCommandSet_" + language.toLowerCase();
if (voiceCommandManager.installedCommandDefinitions.hasKey(commandSetName)) {
var vcd = voiceCommandManager.installedCommandDefinitions.lookup(commandSetName);
} else {
console.log('VCD not installed yet?');
}
}, function (ee) {
console.error("installCommandDefinitionsFromStorageFileAsync error", ee);
});
Commands.xml:
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="BibleCommandSet_en-us">
<AppName> Bible </AppName>
<Example> Go to genesis 1,9 </Example>
<Command Name="goToQuote">
<Example> Go to genesis 1,9 </Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}</ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}{number}</ListenFor>
...
<ListenFor RequireAppName="BeforeOrAfterPhrase"> open {book} {number}{number},{number}{number}</ListenFor>
<Feedback> Ok i'm opening {book} </Feedback>
<Navigate/>
</Command>
</CommandSet>
已修复: 在文件的另一行我有另一个命令集,我确实调用了一个短语列表 "book" 但真实姓名是 "libro"
I integrating Cortana to my app(UWP with Winjs) but when i try to install the VCD file i got that error:Status is 'error', but getResults did not return an error
这是因为您的 VCD 文件有问题 - Command.xml
。由于错误是由VCD文件而不是代码本身引起的,所以您没有得到错误的详细信息。
VCD文件中的特殊字符{}包含了Label属性的值,供PhraseList或PhraseTopic引用。在 ListenFor 或 Feedback 元素中使用。 Feedback 元素中的 PhraseList 或 PhraseTopic 引用必须与同一命令中 ListenFor 元素中的相应引用相匹配。
虽然 PhraseList 或 PhraseTopic 是 CommandSet 的 Optional child,但您在 VCD 文件中为 ListenFor 和 Feedback 元素定义了 {book}
和 {name}
,这需要相应的 PhraseList,其 Label 属性的值为 name
/book
.
我根据你更新了VCD文件,现在代码可以运行成功了。
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="BibleCommandSet_en-us">
<AppName> Bible </AppName>
<Example> Go to genesis 1,9 </Example>
<Command Name="goToQuote">
<Example> Go to genesis 1,9 </Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book}</ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}{number}</ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> open {book} {number}{number},{number}{number}</ListenFor>
<Feedback> Ok i'm opening {book} </Feedback>
<Navigate/>
</Command>
<PhraseList Label="book">
<Item>London</Item>
<Item>Las Vegas</Item>
<Item>Melbourne</Item>
<Item>Yosemite National Park</Item>
</PhraseList>
<PhraseList Label="number">
<Item>2</Item>
<Item>3</Item>
<Item>4</Item>
<Item>5</Item>
</PhraseList>
</CommandSet>
</VoiceCommands>
更详细的VCD文件请参考this document。