Universal Windows App Development with Cortana and the Speech SDK 1 and 2 @Channel9
来源:互联网 发布:文本恢复转换器 mac 编辑:程序博客网 时间:2024/05/20 09:21
Course Website: http://channel9.msdn.com/Series/Universal-Windows-App-Development-with-Cortana-and-the-Speech-SDK
1. Introducing Cortana & Getting Started with Speech
Speech is Personal, Experiential.
Bing powers Cortana. Cloud recognizer runs algorithms
Core Functions: Communicate. Remember. Find.
Fun Cortana. Can tell jokes. Can sing a song.
2. Using Speech Synthesis in Mobile Apps
2.1 Basic Speech Synthesis Integration
2.1.1 Speech Synthesis Options
Speak with default speech settings. -Windows.Media.SpeechSynthesisnamespace
Speak with any installed speech language
Customize Text-to-Speech(TTS) voice with speech synthesis Markup Language (SSML)
TTS support introduced in WIndows Phone 8 SDK and Windows Store 8.1 SDK
2.1.2 In Application Speech Synthesis (Using default voice)
//windows phone store app
Speech Thesis uses a MediaElement control to speak text
// Synthesis<MediaElement Name="audioPlayer" AutoPlay="True".../>
//Fundtion to speak a text stringprivate async void SpeakText(MediaElement audioPlayer, string textToSpeak){SpeechSynthesizer synthesizer=new SpeechSynthesizer();SpeechSynthesisStream ttsStream= await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);audioPlayer.SetSource(ttsStream,"");// This starts the player because AutoPlay="True"}
<strong>Demo to use default voice: </strong>
private async void ButtonLookup_Click(object sender, RoutedEventArgs e) { string location = txtLocation.Text.Trim(); var wr = await owms.GetWeather(location); if (wr != null) { var weatherText = "The current temperature in {0} is {1}°F, with a high today of {2}° and a low of {3}°."; string weatherMessage = string.Format(weatherText, wr.Name, (int)wr.MainWeather.Temp, (int)wr.MainWeather.MaximumTemp, (int)wr.MainWeather.MinimumTemp); lblMessage.Text = weatherMessage; lblTemp.Text = string.Format("{0}°", (int)wr.MainWeather.Temp); ReadText(weatherMessage); } }
private async void ReadText(string mytext) { //Reminder: You need to enable the Microphone capabilitiy in Windows Phone projects //Reminder: Add this namespace in your using statements //using Windows.Media.SpeechSynthesis; // The media object for controlling and playing audio. MediaElement mediaplayer = new MediaElement(); // The object for controlling the speech synthesis engine (voice). using (var speech = new SpeechSynthesizer()) { //Retrieve the first female voice speech.Voice = SpeechSynthesizer.AllVoices .First(i => (i.Gender == VoiceGender.Female && i.Description.Contains("United States"))); // Generate the audio stream from plain text. SpeechSynthesisStream stream = await speech.SynthesizeTextToStreamAsync(mytext); // Send the stream to the media object. mediaplayer.SetSource(stream, stream.ContentType); mediaplayer.Play(); } }
2.1.3 Required Capability
Microphone Capability in package.appxmanifest
-Required for TTS in Windows Phone apps
- Optional for TTS in Windows Store apps
<Capabilities> <Capability Name="internetClientServer"/> <DeviceCapability Name="microphone"/></Capabilities>
2.2 Speech Synthesis Voice Settings
VoiceInformation currentVoice=(VoiceInformation) lstVoice.SelectedItem;speech.voice=currentVoice;SpeechSynthesisStream stream=await speech.SynthesizeTextToStreamAsync(myText);mediaplayer.SetSource(stream,stream.ContentType);mediaplayer.Play();
2.3 Speech Synthesis Markup Language
<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-us'> <voice name='Microsoft Zira Mobile'> <prosody pitch='low' rate='0.9'> This is the text what will be read by the speech synthesizer. <prosody> <voice><speak>
private async void ReadSsmlText(string mytext){VoiceInformation currentVoice=(VoiceInformation)lstVoices.SelectedItem;string Ssml=@"<speak version='1.0' " +"xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='" + currentVoice.Language+"'>"+"<voice name='"+ currentVoice.DisplayName+"'>"+"<prosody pitch='"+lstPitch.SelectedItem.ToString() +"' rate=' "+sldRtae.Value.ToString()+"' </voice></speak>";SpeechSynthesisStream stream=await speech.SynthesizeSsmlToStreamAsync(Ssml);mediaplayer.SetSource(stream,stream.ContentType);mediaplayer.Play();}
2.4 Advanced Text-to-Speech Topics
2.4.1 Save Speech Audio Streams to a File
//open the output streamWidnows.Storage.Streams.Buffer buffer =new Windows.Storage.Streams.Buffer(4096);IRandomAccessStream writeStream=(IRandomAccessStream) await file.OpenAsync(FileAccessMode.ReadWrite);IOutputStream outputStream = writeStream.GetOutputStreamAt(0);DataWriter dataWriter =new DataWriter(outputStream);//copy the stream data into the filewhile(synthesisStream.Position<synthesisStream.Size){await synthesisStream.ReadAsync(buffer,4096,InputStreamOptions.None);dataWriter.WriterBuffer(buffer);}
2.4.2 Play Speech Audio in the Background
MediaElement can play in the background
AudioCategory="BackgroundCapableMedia" for Windows Store 8.1 only
Windows phone 8.1 requires a background audio agent
SystemMediaControls
0 0
- Universal Windows App Development with Cortana and the Speech SDK 1 and 2 @Channel9
- Universal Windows App Development with Cortana and the Speech SDK 3
- Universal Windows App Development with Cortana and the Speech SDK 4
- Universal Windows App Development with Cortana and the Speech SDK 5
- Universal Windows App Development with Cortana and the Speech SDK 6
- Preparing and Submitting an Application to the App Store with xCode4.2 and iOS5 SDK
- Mobile Application Development with SMS and the SIM Toolkit
- Game Development with JavaScript and the Canvas element
- Windows 10 Development with XAML and C 7, 2nd Edition.pdf 2017 英文原版 免费下载
- Windows Developer Power Tools: Turbocharge Windows Development with More Than 140 Free and Open Sour
- Managing Software Development with Trac and Subversion
- Python Development with PyDev and Eclipse - Tutorial
- Servlet and JSP development with Eclipse
- Setting Up the Development Environment for SharePoint 2010 on Windows Vista, Windows 7, and Windows
- Setting Up the Development Environment for SharePoint 2010 on Windows Vista, Windows 7, and Windows
- Setting Up the Development Environment for SharePoint 2010 on Windows Vista, Windows 7, and Windows
- Eclipse AspectJ : Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools
- Six Sigma and the Product Development Cycle
- [Leetcode]Anagrams
- [ios] 模型层中的经典模式代码
- 360扼杀了中国自由软件业
- LeetCode-ZigZag Conversion
- ajax直行两遍的问题
- Universal Windows App Development with Cortana and the Speech SDK 1 and 2 @Channel9
- c++学习笔记 map
- 朱xx 现在开始有点不知道正义的一方是哪边了
- LeetCode: Regular Expression Matching
- curl命令详解
- 植入“电商基因” 传统产业搭上网络快车[图]
- cocos2d-x与着色器设计--入门篇(游云凌天原创)
- Leetcode NO.172 Factorial Trailing Zeroes
- sync logic