歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Windows Phone 8 語音 - Speech for Windows Phone 8

Windows Phone 8 語音 - Speech for Windows Phone 8

日期:2017/3/1 9:53:49   编辑:Linux編程

最近有很多人咨詢我關於 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

Copyright © Linux教程網 All Rights Reserved