通过本例子学习:

  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# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)

    在c#中,string类型转换成DateTime类型是经常用到的,作为基本的知识,这里在此做个小结.一般来说可以使用多种方法进行转换,最常用的就是使用Convert.ToDateTime(string ...

  2. hash命令

    什么是hash ? 在网上找了好久都没找到简截有力的说明.hash 我把它当成是集合,一个hash 就是一个集合,里面字段对应一个元素,元素不重复,字段都不一样. 简单hash 命令 1.hset 哈 ...

  3. miniUI datagrid 获取序号

    获取每一个row以后,其中的row._index字段和页面上显示的序号虽然看起来一样, 但是实际上不是同一个东西,如果用客户端排序模式,排序后,row._index和页面显示的序号就对不上了. 正确的 ...

  4. 创建一个叫做People的类: 属性:姓名、年龄、性别、身高 行为:说话、计算加法、改名 编写能为所有属性赋值的构造方法; (2)创建主类: 创建一个对象:名叫“张三”,性别“男”,年龄18岁,身高1.80; 让该对象调用成员方法: 说出“你好!” 计算23+45的值 将名字改为“李四”

    package com.chuoji; public class People { private String name; private int age; private String sex; ...

  5. 关于cookie的文章(cookie与session机制)

    会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...

  6. code异常处理

    private void copyPrivateRawResuorceToPubliclyAccessibleFile() { InputStream inputStream = null; File ...

  7. [转](三)unity4.6Ugui中文教程文档-------概要-UGUI Basic Layout

    大家好,我是孙广东.   转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:http://www.unityma ...

  8. Giving Data Backup Option in Oracle Forms 6i

    Suppose you want to give the data backup option in Oracle Forms application to some client users, wh ...

  9. C# 调用 Outlook发送邮件实例

    添加引用:Microsoft.Office.Interop.Outlook using System; using System.Collections.Generic; using System.L ...

  10. 前端开发流程之(线上)绝对地址(图片+css+js)

    重要提醒:前端写完-----发邮件通知项目组 1:写好的前段资源包上传到SVN上之后,相关的图片.CSS.js文件要换成线上地址给后台开发. 2:图片-----压缩(https://tinypng.c ...