Saturday, November 23, 2013

Text to Speech in Windows Phone 8

One of the most appealing feature of Windows phone 8 is "Text to speech”. That is the text you write, is spoken. It is interesting and yet so simple to use. This is a quick post describing how to make use of the Speech Synthesizer of windows phone and create the phenomenon of Speech.

Inbuilt is everything, you just need to Create the instance of the class SpeechSynthesizer, give it a voice and use it.

   1: SpeechSynthesizer synth = new SpeechSynthesizer();

Next you need to choose a voice from various installed ones. Voice have, VoiceGender and Language properties to be chosen. For now, let’s choose VoiceGender as Female (well, there is a reason for this) and Language as “en-US”. Here is the line of code to do so:


   1: VoiceInformation femaleEnglishVoices = 
   2:             InstalledVoices.All.FirstOrDefault(x => x.Gender == 
   3:                                 VoiceGender.Female && x.Language.Equals("en-US"));

Finally we have to assign the chosen voice information to our Synthesizer. Which can be done like:


   1: synth.SetVoice(femaleEnglishVoices);

This is it. We are done with the setup, next is to request the phone to speak for you. This can be done by making a asynchronous call to SpeakText() method:


   1: await synth.SpeakTextAsync("Hi Handsome!!");

The Async call is await able, so the await keyword is used. Once the request is made to the synthesizer to speak, it will speak the text written, in a beautiful, female American voice Winking smile.

Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© 2013 Neelesh Vishwakarma
Posts RSS Comments RSS
Back to top