xml code

----------------------------------------------

<Page

x:Class="MyApp.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="using:MyApp"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

mc:Ignorable="d"

Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel>

<TextBox Name="txtInput" Height="100" TextWrapping="Wrap"/>

<Button Margin="0,15,0,10" Content="点击这里,开始识别" Click="onClick" HorizontalAlignment="Stretch"/>

<TextBlock Name="tbDisplay" FontSize="16" Margin="3,13,0,0" Foreground="Yellow"/>

</StackPanel>

</Page>

C#  code

-----------------------------------------------------

public sealed partial class MainPage : Page

{

public MainPage()

{

this.InitializeComponent();

this.NavigationCacheMode = NavigationCacheMode.Required;

}

/// <summary>

/// Invoked when this page is about to be displayed in a Frame.

/// </summary>

/// <param name="e">Event data that describes how this page was reached.

/// This parameter is typically used to configure the page.</param>

protected override void OnNavigatedTo(NavigationEventArgs e)

{

// TODO: Prepare page for display here.

// TODO: If your application contains multiple pages, ensure that you are

// handling the hardware Back button by registering for the

// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.

// If you are using the NavigationHelper provided by some templates,

// this event is handled for you.

}

private async void onClick(object sender, RoutedEventArgs e)

{

Button btn = sender as Button;

btn.IsEnabled = false;

using (SpeechRecognizer recognizer = new SpeechRecognizer())

{

try

{

// 编译所有语法协定

SpeechRecognitionCompilationResult compilationResult = await recognizer.CompileConstraintsAsync();

if (compilationResult.Status == SpeechRecognitionResultStatus.Success)

{

// 开始识别

SpeechRecognitionResult recogResult = await recognizer.RecognizeAsync();

// 显示识别结果

if (recogResult.Status == SpeechRecognitionResultStatus.Success)

{

tbDisplay.Text = "识别完成。";

txtInput.Text = recogResult.Text;

}

}

}

catch (Exception ex)

{

tbDisplay.Text = "异常:" + ex.Message;

}

}

btn.IsEnabled = true;

}

}

最新文章

  1. Oracle转移数据表空间存储位置
  2. linux下JDK1.7安装
  3. c#socket编程基础
  4. java.net.MalformedURLException: Illegal character in URL
  5. ytu 2029: C语言实验——温度转换(水题)
  6. Error:(12) No resource identifier found for attribute &#39;titles&#39; in package &#39;com.itheima52.mobilesafe5
  7. Codeforce 218 div2
  8. FreeRTOS中断优先级配置(重要)
  9. mongodb集群【】
  10. 课后练习:C语言实现Linux命令——od
  11. linux下面的打包压缩命令
  12. Entity Framework (EF) Core工具创建一对多和多对多的关系
  13. spring boot常见问题
  14. Linux内核总结博客 20135332武西垚
  15. 把旧系统迁移到.Net Core 2.0 日记 (12) --发布遇到的问题
  16. 5 -- Hibernate的基本用法 --1 2 基本映射方式
  17. C/C++中的常量到底存在了什么地方
  18. C语言:奇偶归一猜想
  19. 解决sqlplus: command not found
  20. POJ 1755 Triathlon (半平面交)

热门文章

  1. PYTHON 读取ADB记录文件输入ACTIVITY
  2. 11. Linux从入门到进阶
  3. 跟我一起学Go系列:gRPC 全局数据传输和超时处理
  4. 解决linux下按退格键出现 ^? 的问题
  5. centos7下安装mycat中间件 笔记
  6. 【Lucas组合数定理】组合-FZU 2020
  7. IBM java开发面试题
  8. [BSidesCF 2020]Had a bad day 1--PHP伪协议
  9. 13Java进阶——IO、线程
  10. tomcat与springmvc 结合 之---第20篇 springmvc 对于加载的bean对象存储在哪里