Use the SpeechSynthesizer class to enable text-to-read functionality, located in the Windows.Media.SpeechSynthesis namespace. With it we can achieve the sound of fiction, is not very cool. Here is an example of reading the contents of a text block, and remember to check the microphone in the app's function.
For a detailed description of the SpeechSynthesizer class, please refer to:
Http://technet.microsoft.com/zh-cn/sysinternals/system.speech.synthesis.speechsynthesizer (v=vs.95). aspx
The mainpage page layout is as follows:
<grid><stackpanel ><textbox x:name= "Txttosay" width= "+ ″height=" 020″textwrapping= "Wrap"/><button content= "start reading" horizontalalignment= " Center "click=" OnClick "/></stackpanel><mediaelement x:name=" Mdplayer "width="0″height= "0 ″autoplay= "True"/></grid>
The background code is as follows:
Private Async voidOnClick (Objectsender, RoutedEventArgs e) {if(string. Isnullorwhitespace (Txttosay.text))return; SpeechSynthesizer speech=NewSpeechSynthesizer ();//instantiating an object//read aloud textSpeechsynthesisstream stream =awaitSpeech. Synthesizetexttostreamasync (Txttosay.text);//Convert the contents of a text box to a voice stream outputif(Stream! =NULL){ This. Mdplayer.setsource (Stream, stream. ContentType);//Sets the voice flow to the source of MediaElement. }}
SetSource methods for MediaElement see: http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/br244338.aspx
Little Dream Windows Phone 8.1 development: Voice reading