Change output voice in C#

2019-07-23 00:11发布

问题:

Hi I'm just testing SpeechSynthesizer in C# and I want to change the voice.

SpeechSynthesizer reader = new SpeechSynthesizer();


private void button1_Click(object sender, EventArgs e)
        {
            reader.Dispose();
            reader = new SpeechSynthesizer();
            reader.SelectVoiceByHints(VoiceGender.Male);
            reader.Speak("Hi how are you baby");
        }

There is no more Code, just a single button(WinForm). Personally I would say that reader.SelectVoiceByHints(VoiceGender.Male);should be enough. But if I click the button, I still will hear a female voice. What do I need to change? Thank you!

回答1:

I was able to selected specific voices like this:

reader.SelectVoice("Microsoft Zira Desktop");

To get the list of the voices currently installed:

foreach(var voice in reader.GetInstalledVoices()){
    Console.WriteLine(voice.VoiceInfo.Name);

}