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 ...
随机推荐
- Integrated Circuit Intro
1.Noise Margin 不管是TTL还是CMOS Logic Level,都会有门限.如,5V CMOS的VoutH > 4.4V, VoutL <0.33V;而它对应的输入电平Vi ...
- HD2059龟兔赛跑(DP)
题目链接 直接拿来当贪心做了=_=,然后就懵逼了 动态规划,本弱真没想到=_= #include <iostream> #include <cstdio> #include & ...
- 创建 sequence
-- Create sequence create sequence XRMKSD_DET_SEQminvalue 1maxvalue 999999999999999999999999999start ...
- Python QQ群
微信公众号:Python中文社区 Python初级技术交流QQ群:152745094Python高级技术交流QQ群:273186166Python网络爬虫组QQ群:206241755PythonWeb ...
- js 对象属性复制到另一个对象
var obj={a:1,b:2,c:3} var newObj={};for(var i in obj){newObj[i]=obj[i];}console.log(newObj);
- 20145212 《Java程序设计》第6周学习总结
20145212 <Java程序设计>第6周学习总结 学习内容总结 第十章 1.Java将输入/输出抽象化为串流.读取数据对象成为输入流,能向其写入的对象叫输出流. 我从网上找到了一个可以 ...
- Tomcat 用户访问控制
要设置Tomcat下的Host都有哪些ip能访问,可以在conf/server.xml的相应Host元素内加Value标签,示例: <Valve className="org.apac ...
- JSP 原理
参考文献:http://www.cnblogs.com/xdp-gacl/p/3764991.html 一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都 ...
- IE6完美解决fix问题
解决代码: _position: absolute; _top: expression(documentElement.scrollTop + + "px"); 完整代码: kef ...
- Cpu Gpu 内存 显存 数据流
[精]从CPU架构和技术的演变看GPU未来发展 http://www.pcpop.com/doc/0/521/521832_all.shtml 显存与纹理内存详解 http://blog.csdn.n ...