Little Dream Windows Phone 8.1 development: Voice reading

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.