With the release of Windows Phone 8 - it opens up a plethora of new features to Developers. What this means is you can now use all these new features and make your apps feature rich. Today we will talk about one such feature which is addition of "Text  to Speech (TTS)" feature which is now built into Windows Phone 8.

Text to Speech in previous version

In Windows Phone 7.0/7.1 Text to Speech was not built in to the platform. Because of that you had to rely on third party services for this. One such service was from Bind. Using Bind translator service meant that you needed internet connection all the time if you have to provide Text to Speech capability in your apps. The speech from Bing service did not sound human rather it sounded very mechanical.

Text to Speech in Windows Phone 8

In Windows Phone 8 Microsoft has included the Text to Speech feature out of the box in the platform. So the text to speech can be provided in your apps without much sweat. Here are some of the characteristics of TTS in WP8:
  • TTS in WP8 sounds very natural. Speech generated by TTS in WP8 does not sound mechanical.
  • TTS in WP8 works without any internet connection. So this means that you can provide TTS feature in offline mode too i.e. no internet connectivity situation
  • TTS in WP8 supports a wide range of languages. So depending on what culture your app runs, you can customize the speech to sound close to your culture.
  • TTS in WP8 takes only 2 lines of code to get it working. Which means adding speech capability is piece of cake now.

TTS - Hello World

As any programming language example, we will also do a Hello World of Text to Speech to understand how to use this feature. Lets assume you have a button on your screen and lets say its name is "HelloWorldButton". Now on click of the button we will like to say Hello World as a speech. So here is the click event handler code:

private async void HelloWorldButton_Click(object sender, RoutedEventArgs e)
    var synthesizer = new SpeechSynthesizer();
    await synthesizer.SpeakTextAsync("Hello world from WP 8!");

So as you can see - 2 lines is all it takes to create a Text to Speech capability in your apps. If we dont specify

Iterating through all installed voices

By default the voice used for speech is dependent on the culture. The TTS framework comes with a lot of languages and voices which we can use. So different voices differ from each other based on the Gender and the culture they are available in. So if we wanted to change the voice from default to a specific voice, we can make use of SetVoice() available in SpeechSynthesizer class. Here is code to iterate through all the available voices:

private async void AllVoicesButton_Click(object sender, RoutedEventArgs e)
    foreach (var voice in InstalledVoices.All)
        Debug.WriteLine(voice.DisplayName + ", " +
            voice.Language + ", " +
            voice.Gender );
        using (var synth = new SpeechSynthesizer())
            await synth.SpeakTextAsync("Hello world! I'm " + voice.DisplayName + ".");

The debug window would see the following output printed:

Microsoft Zira Mobile, en-US, Female
Microsoft Stefan Mobile, de-DE, Male
Microsoft George Mobile, en-GB, Male
Microsoft Susan Mobile, en-GB, Female
Microsoft Heera Mobile, en-IN, Female
Microsoft Ravi Mobile, en-IN, Male
Microsoft Mark Mobile, en-US, Male
Microsoft Katja Mobile, de-DE, Female
Microsoft Laura Mobile, es-ES, Female
Microsoft Pablo Mobile, es-ES, Male
Microsoft Raul Mobile, es-MX, Male
Microsoft Sabina Mobile, es-MX, Female
Microsoft Julie Mobile, fr-FR, Female
Microsoft Paul Mobile, fr-FR, Male
Microsoft Cosimo Mobile, it-IT, Male
Microsoft Elsa Mobile, it-IT, Female
Microsoft Ayumi Mobile, ja-JP, Female
Microsoft Ichiro Mobile, ja-JP, Male
Microsoft Adam Mobile, pl-PL, Male
Microsoft Paulina Mobile, pl-PL, Female
Microsoft Daniel Mobile, pt-BR, Male
Microsoft Maria Mobile, pt-BR, Female
Microsoft Irina Mobile, ru-RU, Female
Microsoft Pavel Mobile, ru-RU, Male
Microsoft Kangkang Mobile, zh-CN, Male
Microsoft Yaoyao Mobile, zh-CN, Female
Microsoft Danny Mobile, zh-HK, Male
Microsoft Tracy Mobile, zh-HK, Female
Microsoft Yating Mobile, zh-TW, Female
Microsoft Zhiwei Mobile, zh-TW, Male

The namespace in which speech related things can be found is Windows.Phone.Speech.Synthesis namespace. Here is the MSDN lib link for the class:


Through this post i just wanted to highlight the awesomeness WP8 platform provides to application developers in terms of TTS. With just 2 lines of code it is possible to provide text to speech capability in your apps. Hope this article was helpful to you w.r.t getting started with TTS in WP8.

See Also

Another important place to find a huge amount of Windows Phone related articles is the TechNet Wiki itself. The best entry point is Windows Phone Resources on the TechNet Wiki.