TextToSpeech In WPF Using SpeechSynthesizer Class

来源:转载

PPWe will create a WPF application and useSpeechSynthesizer 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

privatevoidbutton_Click(objectsender,RoutedEventArgse){SpeechSynthesizerss=newSpeechSynthesizer();if(radioButtonMale.IsChecked==true){ss.SelectVoiceByHints(VoiceGender.Male);ss.Speak(textBox.Text);}else{ss.SelectVoiceByHints(VoiceGender.Female);ss.Speak(textBox.Text);}}

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: