Universal Windows App Development with Cortana and the Speech SDK 1 and 2 @Channel9
2015-02-26 05:48
585 查看
Course Website: http://channel9.msdn.com/Series/Universal-Windows-App-Development-with-Cortana-and-the-Speech-SDK
Bing powers Cortana. Cloud recognizer runs algorithms
Core Functions: Communicate. Remember. Find.
Fun Cortana. Can tell jokes. Can sing a song.
namespace
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
Speech Thesis uses a MediaElement control to speak text
// Synthesis
<MediaElement Name="audioPlayer" AutoPlay="True".../>
C# code behind: //Speak text
//Fundtion to speak a text string
private 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 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();
}
}
-Required for TTS in Windows Phone apps
- Optional for TTS in Windows Store apps
<Capabilities>
<Capability Name="internetClientServer"/>
<DeviceCapability Name="microphone"/>
</Capabilities>
speech.voice=currentVoice;
SpeechSynthesisStream stream=await speech.SynthesizeTextToStreamAsync(myText);
mediaplayer.SetSource(stream,stream.ContentType);
mediaplayer.Play();
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>
AudioCategory="BackgroundCapableMedia" for Windows Store 8.1 only
Windows phone 8.1 requires a background audio agent
SystemMediaControls
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 appSpeech Thesis uses a MediaElement control to speak text
// Synthesis
<MediaElement Name="audioPlayer" AutoPlay="True".../>
C# code behind: //Speak text
//Fundtion to speak a text string
private 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
<speakversion='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 stream Widnows.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 file while(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 backgroundAudioCategory="BackgroundCapableMedia" for Windows Store 8.1 only
Windows phone 8.1 requires a background audio agent
SystemMediaControls
相关文章推荐
- Universal Windows App Development with Cortana and the Speech SDK 3
- Universal Windows App Development with Cortana and the Speech SDK 6
- Universal Windows App Development with Cortana and the Speech SDK 4
- Universal Windows App Development with Cortana and the Speech SDK 5
- Preparing and Submitting an Application to the App Store with xCode4.2 and iOS5 SDK
- The study of chapter 13 in programming windows with mfc-printing with document and views
- Windows Store App Development Tip and Tricks - GridViewItem
- Windows Developer Power Tools: Turbocharge Windows Development with More Than 140 Free and Open Sour
- Apps and app updates submitted to the App Store must be built with Xcode 5.1.1 or later, and iOS 7 o
- Link - Windows Universal App - Open Url/Rate the App/MessageDialog
- Your version of the Windows SDK is earlier than 6.0 Try setting the 'WINVER' and '_WIN32_WINNT' defi
- this bundle is invalid . new apps and app updates submitted to the app store must be built with publ
- Dual-Booting Ubuntu Linux and Windows 7/Windows Vista (with the Windows bootloader)
- The Study of Programming Windows with MFC--Progress and Animate control
- Game Development with JavaScript and the Canvas element
- 7 developmnet Project with the 2007 Microsoft Office System and Windows SharePoint 2007翻译(1)-feature
- [React + Mobx] Mobx and React intro: syncing the UI with the app state using observable and observer
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built with
- Nullsoft Winamp Plug-in With Bitmapped UI, Docking and Restrictive Resizing - The Code Project - Dialog and Windows
- walk around by The provided App differs from another App with the same version and product ID