Speech Synthesis (Text to Speech) In Windows 8.1 Store Apps

Windows 8.1 adds the ability to perform text to speech using the Windows.Media.SpeechSynthesis namespace.

As a basic example, to say “Hello World” in the default voice:

var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");

var mediaElement = new MediaElement();
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();

You can specify a different speech voice by setting the SpeechSynthesizer’s Voice property.

To get a list of all the installed speech synthesis engines voices that are on the local machine, you can use the SpeechSynthesizer.AllVoices property.

In the example below, we loop through all the installed voices, and ask them to say “Hello World” followed by their names (DisplayName).

var synth = new SpeechSynthesizer();

 foreach (var voice in SpeechSynthesizer.AllVoices)
 {
     synth.Voice = voice;

     var text = "Hello World, I'm " + voice.DisplayName;

     var stream = await synth.SynthesizeTextToStreamAsync(text);

     var me = new MediaElement();
     me.SetSource(stream, stream.ContentType);                
     me.Play();

     await Task.Delay(3000);
 }

SHARE:

Pingbacks and trackbacks (1)+

Add comment

Loading