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 ...
随机推荐
- editGrid自定义列自定义F7
添加自定义列,配置控制自定义F7 自定义F7的地址为连接界面的url /dynamicPage.do?event=initialize&method=doEvent&uipk=com. ...
- jQuery焦点不在输入框内判断不能为空
我能说JS和jquery有时候都有病吗?同样的代码,重敲一遍可以了,再过一会不行了.再试一下重敲,一模一样的代码,也不报错.就是不行.反复折腾.... 我帖上来的是经过了1个小时同等功能的测试OK的, ...
- Objective-C之字典
//字典:(关键字 值) //插入代码字太小 // NSArray *array = [NSArray array];//空数组 // NSDictionary *dict ...
- python和numpy的版本、安装位置
命令行下查看python和numpy的版本和安装位置 1.查看python版本 方法一: python -V 注意:‘-V‘中‘V’为大写字母,只有一个‘-’ 方法二: python --versio ...
- Java Map 简介
AbstractMap, Attributes, AuthProvider, ConcurrentHashMap, ConcurrentSkipListMap, EnumMap, HashMap, H ...
- js 处理日期 看着比较全,备用
http://www.cnblogs.com/endora/archive/2012/12/06/endorahe.html js 处理日期 看着比较全,备用
- Linux下安装setup tools小工具
1, 最小化的linux系统(centos\redhat)默认都是没有安装setup图形小工具的,你输入setup命令会提示 command not found . 如果要使用这个命令安装方法 1.安 ...
- ecshop 变量表
get_goods_info($goods_id) 商品详情 get_sales_count($goods_id) 商品销量 get_promote_goods() 参与促销商品 Mobile
- Linux--文件查找命令
一.简介查找文件的几个命令: 1.which :查找可执行文件的位置 2.whereis:查找文件的位置,可以找到可执行命令和man page 3.locate:配合数据库查看文件位置 4.find: ...
- C#中事件的使用
C#中事件的使用 http://www.cnblogs.com/wayfarer/archive/2004/04/20/6712.html 用一个例子来说明事件的使用. 创建一个简单的类,名为Fil ...