Search code examples
c#voice

Windows console application voice would not change


Here is the code I am writing to change from the female synth voice to a male but it will not change it continues to run the female voice. Any idea why that might be?

//Opening dialog to the user
Console.WriteLine("Console cpu burn by mixedBreed" + "\nPlease wait while I look over your system");
Console.WriteLine();
string author = "Console cpu burn by mixed Breed" + " Please wait while I look over your system";
synth.SelectVoiceByHints(VoiceGender.Male);
synth.Speak(author);

Solution

  • It seems I can also not get the SelectVoiceByHints method to work, the voice never changes. If you want to switch to a male voice though, here is some code that will work:

    using (var synth = new SpeechSynthesizer())
    {
        var voices = synth.GetInstalledVoices().Dump();
        var male = voices.FirstOrDefault(v => v.VoiceInfo.Gender == VoiceGender.Male);
        if (male != null)
        {
            synth.SelectVoice(male.VoiceInfo.Name);
        }
    
        synth.Speak("Hello");
    }