例子:Alarm Clock with voice Commands Sample
通过本例子学习:
- 如何使用自定义字体文件(.TTF)
- 如何播放声音
- 动画的使用
- Speech
- 设置闹铃
- 应用 设置 数据存储到IsolatedStorage
- 如何使用自定义字体文件(.TTF)
<TextBlock x:Name="TimeBlock" HorizontalAlignment="Center" FontFamily="/AlarmClockWithVoice;component/Fonts/Fonts.zip#Quartz MS" Margin="89,272,87,256" FontSize="60">
字体文件BuildAction为Resource的使用方式:
(FontFamily="/AlarmClockWithVoice;component/Fonts/Fonts.zip#Quartz MS")
字体文件BuildAction为Content的使用方式:
(FontFamily="/Assets/Fonts/Fonts.zip#Quartz MS")
注意: Windows Phone 显示应用指定的 FontFamily 中的文本。如果字符不受 FontFamily 支持,或者应用未指定 FontFamily,Windows Phone 将基于字符和用于显示文本的框架元素的 xml:lang 选择一种字体。
- 如何播放声音
以流的方式读取本地文件,并创建SoundEffect对象。
StreamResourceInfo info = App.GetResourceStream(new Uri("Audio/alarm.wav", UriKind.Relative));
Microsoft.Xna.Framework.Audio.SoundEffect alarm = SoundEffect.FromStream(info.Stream);
播放,停止等操作,当前SoundEffect对象的状态SoundState 可以通过 属性State获取:
this.alarmSound.Play();
}
else if (alarmSound.State == SoundState.Playing)
{
this.alarmSound.Stop();
}
}
else if (alarmSound.State == SoundState.Playing)
{
this.alarmSound.Stop();
}
- 动画的使用
小时指针 图片的动画:
<Image x:Name="hourHand" HorizontalAlignment="Left" Height="20" Margin="255,203,0,0" Grid.Row="1" VerticalAlignment="Top" Width="99" Source="/Images/hourHand.jpg" RenderTransformOrigin="0.097,0.5">
<Image.RenderTransform>
<CompositeTransform ScaleX="1.5" ScaleY="1.5" TranslateX="-20.15"/>
</Image.RenderTransform>
</Image>
主要是通过“UIElement.RenderTransform”来实现的: public Transform RenderTransform { get; set; } 要使用多个动画效果,可以使用TransformGroup把多个动画包含其中。
7种变换分别是:
1、TransLateTransForm 移动位置,包含水平移动和垂直移动
2、ScaleTransform 缩放变换 对UI进行放大缩小 包含X轴上的缩放和Y轴上的缩放
3、RotateTransform 旋转 根据定义的旋转点设置角度进行旋转
4、SkewTransform 对UI进行一定角度的倾斜
5、MatrixTransfrom 矩阵变换,一句标准矩阵表示的变换
6、TransformGroup 复合变换按照指定顺序将多个变换复合为一个变换
7、CompositeTransform 组合变换按照固定顺序组合一系列变换
- Speech
语音命令:
1. 右键工程,新 添加 “语音命令项”
<Command Name="alarmTimeSet">
<Example>Set alarm to 7:30 am.</Example>
<ListenFor>Set alarm to {hour} {minute} {ampm}</ListenFor>
<Feedback>Setting the alarm clock</Feedback>
<Navigate Target="MainPage.xaml"/>
</Command> <PhraseList Label="hour">
<Item>1</Item>
<Item>2</Item>
<Item>3</Item>
<Item>4</Item>
<Item>5</Item>
<Item>6</Item>
<Item>7</Item>
<Item>8</Item>
<Item>9</Item>
<Item>10</Item>
<Item>11</Item>
<Item>12</Item>
</PhraseList>
2. 初始化语音命令:
Uri uri = new Uri("ms-appx:///voicecommands.xml", UriKind.Absolute);
await Windows.Phone.Speech.VoiceCommands.VoiceCommandService.InstallCommandSetsFromFileAsync(uri);
语音识别读取:
1. 初始化语音识别相关属性:
using Windows.Phone.Speech.Recognition;
using Windows.Phone.Speech.Synthesis; Speech.recognizer = new SpeechRecognizer();
Speech.synthesizer = new SpeechSynthesizer();
Speech.recognizerUI = new SpeechRecognizerUI(); // Sets the en-US male voice.
IEnumerable<VoiceInformation> enUSMaleVoices = from voice in InstalledVoices.All
where voice.Gender == VoiceGender.Male
&& voice.Language == "en-US"
select voice; Speech.synthesizer.SetVoice(enUSMaleVoices.ElementAt());
2. 朗读文本:
await Speech.synthesizer.SpeakTextAsync("Alarm is now set for "
+ Settings.alarmTime.Value.Hours + " " + Settings.alarmTime.Value.Minutes);
- 设置闹铃
1. 初始化设置闹钟:
using Microsoft.Phone.Scheduler;
public static Alarm alarm;
Clock.alarm = new Alarm("alarm");
Clock.alarm.ExpirationTime = DateTime.MaxValue;
Clock.alarm.RecurrenceType = RecurrenceInterval.Daily;
Clock.alarm.Sound = new Uri("Audio/alarm.wav", UriKind.Relative);
Clock.alarm.Content = "Alarm ringing!";
2. 添加到SchduleActionService,一个专门用于管理计划任务的类:
ScheduledActionService.Add(Clock.alarm);
3.根据用户操作输入,设定时间:
参数为 年月日时分秒, 1 表示everyday。
Clock.alarm.BeginTime = new DateTime(, , , hours, minutes, );
- 应用 设置 数据存储到IsolatedStorage
using System.IO.IsolatedStorage; public class StoredItem<T>
{
private T value;
private T defaultValue;
private string name;
private bool needRefresh; public StoredItem(string _name, T _defaultValue)
{
this.name = _name;
this.defaultValue = _defaultValue; // If isolated storage doesn't have the value stored yet
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue(this.name, out this.value))
{
this.value = _defaultValue;
IsolatedStorageSettings.ApplicationSettings[this.name] = _defaultValue;
} this.needRefresh = false;
} public T Value
{
get
{
if (this.needRefresh)
{
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue(this.name, out this.value))
{
IsolatedStorageSettings.ApplicationSettings[this.name] = this.defaultValue;
this.value = this.defaultValue;
}
this.needRefresh = false;
} return this.value;
}
set
{
if (this.value.Equals(value))
return; // Store the value in isolated storage.
IsolatedStorageSettings.ApplicationSettings[this.name] = value;
this.needRefresh = true;
}
} public T DefaultValue
{
get
{
return this.defaultValue;
}
} public string Name
{
get
{
return this.name;
}
} public override string ToString()
{
return this.name
+ " with value: " + this.value.ToString()
+ ", default value: " + this.defaultValue.ToString();
} public void ForceRefresh()
{
this.needRefresh = true;
}
}
例子:Alarm Clock with voice Commands Sample的更多相关文章
- Centos 6.5 安装 chrome , mplayer , alarm , clock
http://my.oschina.net/jianweizhang/blog/306946 Chrome wget http://chrome.richardlloyd.org.uk/install ...
- Codeforces Round #451 (Div. 2) [ D. Alarm Clock ] [ E. Squares and not squares ] [ F. Restoring the Expression ]
PROBLEM D. Alarm Clock 题 OvO http://codeforces.com/contest/898/problem/D codeforces 898d 解 从前往后枚举,放进 ...
- 例子:Bluetooth app to device sample
本例子演示了: 判断蓝牙是否打开,是通过一个HRsult值为0x8007048F的异常来判断的 catch (Exception ex) { if ((uint)ex.HResult == 0x800 ...
- Voice Commands (VCD) Cortana 微软小娜示例
Cortana 样品 您可以创建自定义功能Cortana使用Cortana技能装备或遗留的声音命令(VCD)平台. 在这里,你可以找到相关的样品: Cortana技能装备 目前Cortana技巧是建立 ...
- Gym 100531A Alarm Clock (水题)
题意:给定一个被高亮的数,问你是不是有个时间恰好高亮是这个数. 析:直接暴力,直接暴力,枚举每一位时间,当然也可以枚举时间,能找到就是有,找不到就算了. 代码如下: #pragma comment(l ...
- 【Codeforces Round #451 (Div. 2) D】Alarm Clock
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) ...
- 【HDOJ】2395 Alarm Clock
水题. /* 2395 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...
- Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- cf898d Alarm Clock
区间上有 \(n\) 个点,问你为达到目的:长度为 \(m\) 的区间内点的个数都 $ < k$需要去掉多少个点. 贪心.每个区间我们总是去掉最后的,也就是说除非万不得已我们是不会去掉点的. 队 ...
随机推荐
- 【svn】一个设置,少写几个字
以下场景仅适用于修改bug的时候,在提交代码的时候少写几个字,嘿嘿: 1.打开[SVN 属性],在代码目录右键 2.打开BUG跟踪设置窗口 3.输入BUG的URL前缀以及%BUGID%,如 复选框,建 ...
- mysql++的release版本当机的问题
今天用mysql++的release写例子,总是当机,仔细查了一下,发现在编mysqlpp库的时候,代码生成设置成了MDD,改成MD就好了.
- 自定义view
这两篇文章不可错过,是最靠谱的基础文献.总的来说,如果想完全定制,就继承与于View类:如果只是在原有控件基础上拓展,那就继承TextView.Button或者LinearLayout等.接下来,就以 ...
- [转]Git调用第三方对比工具beyondCompare
点击阅读原文 对于我这种 git 命令行小白来说, git 自带的对比工具各种水土不服,想念以前的 svn 小乌龟 + beyondCompare 的日子...纠结完 gitHub client 未果 ...
- win7下JDK环境变量设置方法
来源于:http://jingyan.baidu.com/article/e9fb46e1b2b3347521f766c1.html
- hdu 5779 Tower Defence
题意:考虑由$n$个结点构成的无向图,每条边的长度均为$1$,问有多少种构图方法使得结点$1$与任意其它节点之间的最短距离均不等于$k$(无法到达时距离等于无穷大),输出答案对$1e9+7$取模.$1 ...
- php 面向对象中的魔术方法
1.__construct() 实例化对象是被自动调用.当__construct和以类名为函数名的函数 同时存在时调用__construct,另一个不背调用. 类名为函数名的函数为老版的构造函数. 2 ...
- 配置org.springframework.scheduling.quartz.CronTriggerBean (转载)
在项目中又用到了定时器,对于定时器的应用总是模模糊糊的,今天结合网上找到的资料与自己在项目中写的简单地在此写一下,以备需要时查阅. 一个Quartz的CronTrigger表达式分为七项子表达式,其中 ...
- 学的一点点ps
从C语言的代码中解脱开始学ps,看到色彩鲜明的东西,心里只有那么爽.哈哈.只学习3天,虽然只是一些皮毛,可还是学到了一些以前不知道的东西.让我对ps多了很多兴趣,决定以后要自学更多的ps技能.要给图片 ...
- 机器学习职位 & 面经
http://www.cnblogs.com/peileyuan/p/4775453.html <浅谈机器学习的职业发展方向> http://blog.sina.com.cn/s/blog ...