通过本例子学习:

  1. 如何使用自定义字体文件(.TTF)
  2. 如何播放声音
  3. 动画的使用
  4. Speech
  5. 设置闹铃
  6. 应用 设置 数据存储到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的更多相关文章

  1. Centos 6.5 安装 chrome , mplayer , alarm , clock

    http://my.oschina.net/jianweizhang/blog/306946 Chrome wget http://chrome.richardlloyd.org.uk/install ...

  2. 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 解 从前往后枚举,放进 ...

  3. 例子:Bluetooth app to device sample

    本例子演示了: 判断蓝牙是否打开,是通过一个HRsult值为0x8007048F的异常来判断的 catch (Exception ex) { if ((uint)ex.HResult == 0x800 ...

  4. Voice Commands (VCD) Cortana 微软小娜示例

    Cortana 样品 您可以创建自定义功能Cortana使用Cortana技能装备或遗留的声音命令(VCD)平台. 在这里,你可以找到相关的样品: Cortana技能装备 目前Cortana技巧是建立 ...

  5. Gym 100531A Alarm Clock (水题)

    题意:给定一个被高亮的数,问你是不是有个时间恰好高亮是这个数. 析:直接暴力,直接暴力,枚举每一位时间,当然也可以枚举时间,能找到就是有,找不到就算了. 代码如下: #pragma comment(l ...

  6. 【Codeforces Round #451 (Div. 2) D】Alarm Clock

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) ...

  7. 【HDOJ】2395 Alarm Clock

    水题. /* 2395 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...

  8. 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 ...

  9. cf898d Alarm Clock

    区间上有 \(n\) 个点,问你为达到目的:长度为 \(m\) 的区间内点的个数都 $ < k$需要去掉多少个点. 贪心.每个区间我们总是去掉最后的,也就是说除非万不得已我们是不会去掉点的. 队 ...

随机推荐

  1. C# 使用 Abot 实现 爬虫 抓取网页信息 源码下载

    下载地址 ** dome **

  2. LeetCode----66. Plus One(Java)

    package plusOne66; /* Given a non-negative number represented as an array of digits, plus one to the ...

  3. KVM虚拟机virsh常用参数

    线上虚拟机挂了,常用的命令忘了,记录下 链接:http://www.ibm.com/support/knowledgecenter/zh/linuxonibm/liabp/liabpcommonvir ...

  4. 流镜像(华为S9306和S5700)

    流镜像是指将设备.端口或者VLAN内收.发的指定类型报文复制到观察端口上,监控设备只对指定类型报文进行监测. 流镜像有基于ACL和基于MQC(即复杂流分类)两种配置方式.前者配置简便,但是没有后者支持 ...

  5. asp.net 微信支付 错误解决方案

    asp.net 微信支付 错误解决方案 在网上看到有人解决方案为: 解决方法 出现这种错误网上查出现有的原因是: 订阅号没有相关的权限 账号没有认证,没有相关的权限 那么这里遇到问题两种都不是.开发账 ...

  6. 【Spring】搭建最简单的Spring MVC项目

    每次需要Spring MVC的web项目测试一些东西时,都苦于手头上没有最简单的Spring MVC的web项目,现写一个. > 版本说明 首先要引入一些包,Spring的IOC.MVC包就不用 ...

  7. mac 启动apache + php

    一.启动Apache 在终端里输入命令,启动 Apache: sudo apachectl start 关闭 Apache: sudo apachectl stop 重启 Apache:sudo ap ...

  8. Deep Learning 15:RBM的学习

    RBM是深度学习的核心,所以必须彻底清楚地理解RBM原理.推导及其训练方法 1.读学位论文“基于深度学习的人脸识别研究”: 对RBM.DBN的介绍比较详细,可以作为基础阅读,再去读英文论文. 2.RB ...

  9. 安卓设备通过USB接口读取UVC摄像头权限问题

    libusb for Android================== Building:--------- To build libusb for Android do the following ...

  10. 用单分子测序(single-molecule sequencing)和局部敏感哈希(locality-sensitive hashing)来组装大型基因组

    Assembling large genomes with single-molecule sequencing and locality-sensitive hashing 好好读读,算法系列的好文 ...