TextToSpeech In WPF Using SpeechSynthesizer Class

PPWe will create a WPF application and use SpeechSynthesizer class and methods to enter text in Textbox and then convert into speech.
Step 1: Create New Project and go to '
Create New Project, Select File, New, then Project'.

Select Windows and Create WPF application as per the following screen,
Step 2: From the toolbox add 1 Textbox, 1 button and 2 Radiobuttons and design your layout as in the following,
Step 3: Right click on Project and add reference 'System.speech'
Step 4: Add the Namespace: System.Speech.Synthesis  in your .cs file and add code on button click event as per the following screen,
Use SelectVoiceByHints Method and pass VoiceGender.Male or for VoiceGender.Female.

Use Speak method for TextToSpeech. 
code : button_Click 
  1. private void button_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.     SpeechSynthesizer ss = new SpeechSynthesizer();  
  4.     if (radioButtonMale.IsChecked == true)  
  5.     {  
  6.         ss.SelectVoiceByHints(VoiceGender.Male);  
  7.         ss.Speak(textBox.Text);  
  8.     }  
  9.     else  
  10.     {  
  11.         ss.SelectVoiceByHints(VoiceGender.Female);  
  12.         ss.Speak(textBox.Text);  
  13.     }  
  14. }  
Step 5: Now run the application and enter some text in textbox and check on 'Male Voice' and hit 'Click Here' Button. Also check for 'Female Voice' option.
For more details download the attached code.
Hope you liked this article.