首页 / 操作系统 / Linux / Windows Phone 8 语音 - Speech for Windows Phone 8
最近有很多人咨询我关于 windows phone 8 语音识别方面的用法,今天我就在这里给大家总结一下以便大家学习交流在windows phone8中语音可以理解为三部分功能即: 语音控制 voice commands, 语音识别 speech recognition, 文字语音 text-to-speech (TTS)。升级到WP8必需知道的13个特性 系列文章目录地址:http://www.linuxidc.com/Linux/2013-08/89003.htm在写程序之前要先把你的WP8 声明成支持Voice command的APP 1. 语音控制 voice commands 对应 ID_CAP_SPEECH_RECOGNITION, ID_CAP_MICROPHONE, and ID_CAP_NETWORKING capabilities in the app manifest file 语音控制顾名思义可以使用语音命令来操作应用程程序,包括启动和页面跳转。首先你要现在你的WP8项目中添加一个VCD文件,它的用途就是来声明你的WP8App 可以接受那些 语音命令并且会给用户那些语音反馈以及会执行那些动作。例如: CommandPrefix 就是声明你的应用程序打开关键字 Command Name 声明你的应用可以识别执行那些动作 Navigate 可以将包含关键字的命令导航到特定页面。 当然你还要在你的系统中注册你的应用是一个支持语音控制的应用 这里MSDN推荐用一个单独的方法承载 public async void InitCommand() { await VoiceCommandService.InstallCommandSetsFromFileAsync(new Uri("ms-appx:///VoiceCommandDefinition1.xml")); }
// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { InitCommand(); } 既然你的应用可以支持语音的目标导航当然在我们的目标页面也是可以拿到用户的语音参数的,当然请放心这里我们的SDK已经帮我们吧语音翻译成文字了,相信大家处理文字还会很得心应手的.你只重写一下你的目标页面的 onNavigatedTo事件 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e);
// Is this a new activation or a resurrection from tombstone? if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New) {
// Was the app launched using a voice command? if (NavigationContext.QueryString.ContainsKey("voiceCommandName")) {
// If so, get theon name of the voice command. string voiceCommandName = NavigationContext.QueryString["voiceCommandName"];
// Define app actions for each voice command name. switch (voiceCommandName) { case "showWidgets": string viewWidget = NavigationContext.QueryString["widgetViews"];
// Add code to display specified widgets. break;
// Add cases for other voice commands. default:
// There is no match for the voice command name. onbreak; } } } } msdn参考: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206959(v=vs.105).aspx