WP8.1下 Cortana语音命令 VCD文件 设计
Windows Phone8.1下的Cortana,可以通过语音的方式,打开、设置应用,进行页面跳转、执行任务。
我们先要创建VCD(VoiceCommand.xml)文件
<?xml version="1.0" encoding="utf-8" ?> <VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<!--1.0下,不含PhraseTopic元素, 不能识别任意的短语; 1.1下没有此限制-->
<CommandSet xml:lang="zh-cn" Name="CommanSet1"> <!--中文-->
<CommandPrefix>快递</CommandPrefix> <!--程序名, 无次元素则为默认程序名(这个只是为了说话方便设定的)-->
<Example>查快递</Example>
<!-- 以上两个将会显示在Cortana查看更多内--> <!--当上面点入后会进入到说话示例-->
<!--命令--> <Command Name="Command1">
<Example>扫描条形码</Example>
<ListenFor>扫描条形码</ListenFor>
<Feedback>跳转到条形码扫描页面</Feedback>
<Navigate/>
</Command>
<Command Name="Command2">
<Example>查询 + {快递名称}</Example>
<ListenFor>查询{ExpressName}</ListenFor>
<Feedback>查询{ExpressName}</Feedback>
<Navigate/>
</Command> <Command Name="Command3">
<Example>查询 + {快递名称} + {运单号}</Example>
<ListenFor>[查询] {ExpressName} [运单][运单号] {order}</ListenFor> <!-- []表示可有可无的单词或短语 -->
<Feedback>查询 {ExpressName} 运单号:{order}</Feedback>
<Navigate/>
</Command> <!--0个或一个-->
<PhraseList Label="ExpressName"> <!--用大括号 {}引用 同时用于ListenFor、Feedback元素中-->
<Item>申通快递</Item>
<Item>圆通快递</Item>
<Item>顺丰快递</Item>
</PhraseList> <PhraseTopic Label="order" Scenario="Short Message"> <!--可识别任意语句-->
<Subject>Order</Subject>
</PhraseTopic> </CommandSet>
</VoiceCommands>
上面的VCD文件中3个语音命令功能:
Command1: 识别“快递 扫描条形码”,并跳转到扫描页面。
Command2: 识别“快递 查询{快递名称}”, 并跳转到主页面,将识别到的快递名称; {快递名称}为申通、圆通、顺丰中一个
Command3: 识别“快递 [查询] {快递名称} [运单][运单号] {自己说的话,这里为运单号}”; []为可有可无
这三个命令应该可以代表所有了吧。
VCD文件创建好后,就开始初始化VCD文件 主页面中:
using Windows.Media.SpeechRecognition; protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (VoiceCommandManager.InstalledCommandSets.Count == )
{
StorageFile file = await Windows.ApplicationModel.Package.Current.
InstalledLocation.GetFileAsync("VoiceCommand.xml");
await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file);
}
}
从Cortana执行语音命令
App.cs中
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.VoiceCommand) //应用在语音命令后激活
{
VoiceCommandActivatedEventArgs voiceCommandArgs = args as VoiceCommandActivatedEventArgs;
Frame rootFrame = new Frame(); string result = voiceCommandArgs.Result.Text; //识别到的结果
if (result.Contains("运单"))
rootFrame.Navigate(typeof(MainPage), voiceCommandArgs);//传递参数,之后在新页面接受处理
else if (result.Contains("条形码"))
rootFrame.Navigate(typeof(BarCodeScanPage));
else if (result.Contains("查询"))
rootFrame.Navigate(typeof(MainPage), voiceCommandArgs);
Window.Current.Content = rootFrame;
Window.Current.Activate();
}
}
这样就完成了,小娜真的很好用. 以后的应用应该很多都会支持语音命令吧。
WP8.1下 Cortana语音命令 VCD文件 设计的更多相关文章
- linux 下用find命令查找文件,rm命令删除文件
linux 下用find命令查找文件,rm命令删除文件. 删除指定目录下指定文件find 要查找的目录名 -name .svn |xargs rm -rf 删除指定名称的文件或文件夹: find -t ...
- Windows phone 8.1应用集成cortana语音命令
微软推出小娜已经有一段时间了,最近恰好在研究其用法,就随便写点记录一下自己的心得. 在研究时参考了@王博_Nick的博客:http://www.cnblogs.com/sonic1abc/p/3868 ...
- windows下使用RoboCopy命令进行文件夹增量备份
RoboCopy,它是一个命令行的目录复制命令,自从Windows NT 4.0 开始就成为windows 资源工具包的一部分,然后在Windows Vista.Windows 7和 Windows ...
- Mac OS 终端下使用 Curl 命令下载文件
在 mac os下,如何通过命令行来下载网络文件?如果你没有安装或 wget 命令,那么可以使用 curl 工具来达到我们的目的. curl命令参数: curl 'url地址' curl [选项] ' ...
- CMD下利用subst命令将一个文件夹镜像成本地的一个虚拟磁盘
我们都知道net use可以建立网络驱动器映射,这里不说了. 我今天刚看到这命令的,叫镜像虚拟磁盘subst命令,这个命令可以简化好多操作,比如一个常用的文件放在一个路径很深的文件夹中,每次我们想要操 ...
- linux 下使用scp命令传输文件
scp -P 1234 /home/wakasann/test.txt wakasann@192.168.1.30:/var/www/html/ 使用 1234端口,将 test.txt文件传输到服务 ...
- mac下通过mdfind命令搜索文件
mdfind命令就是Spotlight功能的终端界面,这意味着如果Spotlight被禁用,mdfind命令也将无法工作.mdfind命令非常迅速.高效.最基本的使用方法是: mdfind -name ...
- ubuntu 下通过ftp命令下载文件
/*连接*/ $ ftp 192.168.180.2Connected to 192.168.180.2.Name (192.168.180.2:rivsidn): admin Password: ...
- windows下使用linux命令搜文件
在linux系统的黑幕下,我们只能通过find命令来搜文件,而在windows的界面里,我们只能通过搜索框来搜.两者各有利弊,前者单调但高效,后者用户体验好却比较慢.能不能在windows使用linu ...
随机推荐
- UVa 437 The Tower of Babylon(经典动态规划)
传送门 Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details ...
- Linux部分命令使用记录(实时更新)
1. 实时监控文件内容变化 tail -f xxx 2. 查看文件前5行 head -5 xxx 3. ssh对话失效后关闭对话(可以避免直接关闭终端) ~. (好像显示有问题,按钮是 -.) 4. ...
- python zip()
>>> help(zip) Help on built-in function zip in module __builtin__: zip(...) zip(seq1 [, seq ...
- JZOJ P1830[9.30]送牛奶
传送门 临近NOIp,写一些简单题. 二分+BFS,注意的是要把数组开小点,有效减少memset的时间. //OJ 1830 //by Cydiater //2016.9.22 #include &l ...
- linux认识第一面
一.领域问题: 在客户端领域,windows始终占据了优势地位.而在服务器领域,全球98%的都是在用linux.因为linux作为服务器的载体,便宜又安全. 二.linux是基于内核的编写工具,在li ...
- 【原】react做tab切换的几种方式
最近搞一个pc端的活动,搞了一个多月,甚烦,因为相比于pc端,更喜欢移动端多一点.因为移动端又能搞我的react了. 今天主要总结一下react当中tab切换的几种方式,因为tab切换基本上都会用到. ...
- js JS 浮点计算BUG
Number.prototype.toRound = function(d) { var s=this+"";if(!d)d=0; if(s.indexOf(".&quo ...
- 如何修改Linux主机名
Linux 下什么都比较麻烦,就连修改主机名也不例外.我们就下文说一下具体方法. Linux 安装好后,其默认的主机名是 localhost.修改 Linux 主机名需要3步. 使用 hostname ...
- PHP中“简单工厂模式”实例讲解
原创文章,转载请注明出处:http://www.cnblogs.com/hongfei/archive/2012/07/07/2580776.html 简单工厂模式:①抽象基类:类中定义抽象一些方法, ...
- super 要点
class Grandparent { public Grandparent() { System.out.println("GrandParent Created."); } p ...