如何修改柯塔娜语音激活的C#命令(XML)? [英] How to modify Cortana Voice Activation commands (XML) in C#?

查看:186
本文介绍了如何修改柯塔娜语音激活的C#命令(XML)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有柯塔娜落实到我的Silverlight应用程序。语音命令存储在CortanaCommands.xml,这里是代码:

I currently have Cortana implemented into my Silverlight app. The voice commands are stored in CortanaCommands.xml, here is the code:

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<CommandSet xml:lang="en-US">
<CommandPrefix>Dr. Bailey</CommandPrefix>
<Example> Open app to take dictation </Example>

<Command Name="Text">
  <Example> Is it going to rain? </Example>
  <ListenFor> [create] {dictation} </ListenFor>
  <Feedback> "" </Feedback>
  <Navigate Target="/Views/CortanaText.xaml" />
</Command>

<PhraseTopic Label="dictation" Scenario="Dictation">
  <Subject> Cal 123 </Subject>
</PhraseTopic>
</CommandSet>
</VoiceCommands>"

在这个例子中,如果用户部署柯塔娜并说博士。贝利,是它会下雨吗?,然后应用程序导航到CortanaText.xaml,这是硬编码到XML,我希望用户能够定制自己的命令前缀和他们的命令。

In this example, if the user deploys Cortana and says "Dr. Bailey, is it going to rain?", then the app navigates to the CortanaText.xaml. This is hard coded into the XML, and I want the user to be able to customize their Command Prefix and their Command.

通过利用2文本框,我有编码在C#中包含整个XML字符串,但插入从包含新的命令前缀和命令的文本框的选择。这个字符串被称为cortanaXMLstring什么是覆盖在CortanaCommands.xml与新字符串中的现有代码的最佳方式?我想那会是不是修改现有的XML 2个不同的领域更容易。我也认为有可能删除CortanaCommands。 XML(使用C#代码),然后创建一个XML一遍,只需插入字符串,因为该字符串包含所有所需的XML文本?或者,是否有关于如何获得在这两个领域的任何其他建议XML修改?这是命令前缀和命令示例感谢您可以提供任何帮助!

By utilizing 2 textboxes, I have coded in C# a string that contains the entire XML, but inserting the choices from the the text boxes that contain the new Command Prefix and Command. This string is called cortanaXMLstring. What is the best possible way to overwrite the existing code in CortanaCommands.xml with the new string? I figured that would be easier than modifying 2 different areas of the existing XML. I also thought it might be possible to delete the CortanaCommands.xml (using c# code), and then creating that XML all over again by simply inserting the string, since the string contains all of the text needed for the XML? Or, are there any other suggestions on how to get these 2 fields in the XML modified? It's the Command Prefix and the Command Example. Thank you for any help that can be provided!

推荐答案

所以我们解决这一定量的时间之后。

So we solved this after some amount of time.

首先,我们加载的XML文件导入到独立存储和使用来自独立存储加载的VCD文件

First, we loaded the XML file into Isolated Storage and loaded the VCD file from isolated storage using

await VoiceCommandService.InstallCommandSetsFromFileAsync(new Uri("ms-appdata:///local/CortanaCommands.xml", UriKind.RelativeOrAbsolute));



而不是

instead of

MS-APPX:///CortanaCommands.xml

MS-应用程序数据:///local/CortanaCommands.xml

什么是负载从独立存储文件夹而不是从XAP文件。

Is what loads from the Isolated Storage folder instead from the XAP file.

然后,我们完全重写XML文件中的代码替换

Then we completely rewrote the xml file in code replacing the

< CommandPrefix> < ListenFor>

与从两个文本框的用户输入。我们认为装到一个流并用

with user input from the two text boxes. We loaded that into a stream and used

document.Root.RemoveAll();

要使用新的数据和重新加载

to remove the old xml information from CortanaCommands.xml and rewrote the stream into xml using our new data and reloaded

VoiceCommandService.InstallCommandSetsFromFileAsync(new Uri("ms-appdata:///local/CortanaCommands.xml", UriKind.RelativeOrAbsolute));



尽一切允许用户添加自定义的命令前缀和词组推出我们想要的页面发射。这可以用来在XML文件来改变任何东西,完全重写VCD到用户的喜欢。

Doing all that allows for the user to add custom Command Prefix and phrase to launch the page we wanted to launch. This can be used to change anything in the xml file and completely rewrite the VCD to the users liking.

我要指出,我们的目的,我们并不需要的词组话题,因为我们只用了一个导航命令。我们删除了这句话的话题,因为它是可选无论如何,改变了[创建] {}听写在listenfor到是不是要下雨了

I should mention that for our purposes, we did not need the phrase topic as we only were using one navigation command. We deleted that phrase topic as it is optional anyway and changed the [create] {dictation} in the listenfor to "is it going to rain"

这篇关于如何修改柯塔娜语音激活的C#命令(XML)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆