Change text to speech gender

I want to make a text-to-speech program for my interactive typing. I used the System.Speech library, but the voice is always female. I would like some sentences to be read with a male voice, and some with a female voice. (These two voices are the only ones I need.)

I use Windows 8 Pro and Visual Studio 2010. I see only one voice pack - Microsoft Zira Desktop.

My code is as follows. How can I customize the use of male voice?

 SpeechSynthesizer synth = new SpeechSynthesizer(); synth.Rate = 1; synth.Volume = 100; synth.SelectVoiceByHints(VoiceGender.Male,VoiceAge.Adult); synth.SpeakAsync(label18.Text); 
+6
source share
1 answer

First you need to know which voices are installed, you can do this with the GetInstalledVoices method of the SpeechSynthesizer class: http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.getinstalledvoices.aspx

Once you make sure you have a male voice installed, you can simply switch to SelectVoiceByHints See: http://msdn.microsoft.com/en-us/library/ms586877

 using (SpeechSynthesizer synthesizer = new SpeechSynthesizer()) { // show installed voices foreach (var v in synthesizer.GetInstalledVoices().Select(v => v.VoiceInfo)) { Console.WriteLine("Name:{0}, Gender:{1}, Age:{2}", v.Description, v.Gender, v.Age); } // select male senior (if it exists) synthesizer.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Senior); // select audio device synthesizer.SetOutputToDefaultAudioDevice(); // build and speak a prompt PromptBuilder builder = new PromptBuilder(); builder.AppendText("Found this on Stack Overflow."); synthesizer.Speak(builder); } 

See this for further explanation: how to change gender and age of voice synthesizer in C #?

+6
source

Source: https://habr.com/ru/post/971546/


All Articles