none
Text to speech RRS feed

  • Question

  • Hello  everyone!

    Windows 10 home (hungarian) runs on my machine (asus vivobook).

    I would write a desktop application in C # with English and Hungarian text reading.

    English reading already works fine, but only female voice (Zira) is available. 

    Is there a chance to change the female voice to a male voice (like David or George) or forget it?

    Thank you in advance for your answer(s).
    Saturday, December 7, 2019 4:51 PM

All replies

  • Hi Riha46,

    Thank you for posting here.

    For your question, you want to change the sound of voice from female to male.

    First of all,  it is necessary for you to download the corresponding voice pack.

    Setting => Time & Language

    And then, you can use the following code to change the voice.

            private void Button1_Click(object sender, EventArgs e)
            {
                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);
                    }
    
                    // If you just need a male voice, you can use this way
                    synthesizer.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Adult);
    
                    //If you need a specific person's voice, you can specify it with a person's name like this.
    
                    synthesizer.SelectVoice("Microsoft David Desktop");
                    // select audio device
                    synthesizer.SetOutputToDefaultAudioDevice();
                    // build and speak a prompt
                    PromptBuilder builder = new PromptBuilder();
                    builder.AppendText(textBox1.Text);
                    synthesizer.Speak(builder);
                }
            }

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 9, 2019 2:28 AM
  • Hi Timon,

    Thank you for the reply.

    I'm stuck here:
    First of all,  it is necessary for you to download the corresponding voice pack.

    Please help me:
    Which is the voice pack that George has  and where can I find that?

    Best Regards,

    Riha



    • Edited by Riha46 Thursday, December 19, 2019 4:25 PM
    Thursday, December 19, 2019 4:22 PM
  • Hi Riha,

    Thanks for your feedback.

    Windows provides English versions for multiple countries to choose from, and each version provides several people's voices.

    You can download the voice pack according to the following steps.

    

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Friday, December 20, 2019 1:53 AM
  • Hi Timon,

    Thank you for the reply.

    I got stuck again:
    Do not go to step 6.

    The row is gray.

    Best Regards,

    Riha


    Riha46

    Saturday, December 21, 2019 5:17 PM
  • Hi Riha,

    You may have downloaded the language pack.

    I downloaded the American English language pack, so my American English options are grayed out.

    Please check it.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 25, 2019 1:38 AM
  • Hi Timon,
    Thanks for the reply.

    There was an install as you wrote, but there was no download. I just downloaded the sounds. Now there are George, Hazel, Susan and Szabolcs.

    private void say_George(string szovega)
            {
    
    
                SpVoice voice = new SpVoice();
                ISpVoice pVoice = (ISpVoice)voice;
    
                SpObjectTokenCategory otc = new SpObjectTokenCategory();
    
                otc.SetId("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices");
    
                ISpeechObjectTokens tokenEnum = otc.EnumerateTokens();
                int nTokenCount = tokenEnum.Count;
    
                foreach (ISpeechObjectToken sot in tokenEnum)
                {
    
                    {
                        pVoice.SetVoice((ISpObjectToken)sot);
                        try
                        {
    
                            pVoice.Speak(szovega, 0, out uint n);
                        }
                        catch (System.Exception)
                        {
                            Console.WriteLine("Cannot speak with the voice : {0}", sot.GetDescription());
                        }
                        Marshal.ReleaseComObject(sot);
                    }
                }
            }

    How do I select a sound?

    Best Regards,

    Riha


    Riha46

    Saturday, December 28, 2019 11:19 AM
  • Hi Riha,

    There are two ways to choose a voice.

    1. Via Windows: Setting-> Time & Language-> Speech-> Choose a voice(I did n’t download the speech package, so it ’s gray.).

    2. Specify by programming: George is just an abbreviation.

    You can list the full names of all installed voices first, and then select the one you want to use.

               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);
                    }
                    //If you need a specific person's voice, you can specify it with a person's name like this.
                    synthesizer.SelectVoice("Microsoft David Desktop");
                    // select audio device
                    synthesizer.SetOutputToDefaultAudioDevice();
                    // build and speak a prompt
                    PromptBuilder builder = new PromptBuilder();
                    
                    builder.AppendText("The strings to voice.");
                    synthesizer.Speak(builder);
                }

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, December 30, 2019 1:57 AM
  • Hi Timon,
    Thanks for the reply.

    Unfortunately, your answer didn't help.
    I don't need David, but George.
    George is here ("HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Speech_OneCore \\ Voices") but not alone.  Hazel, Suzan and Szabolcs are here.

    How do I choose George?

    Best Regards,

    Riha


    Riha46

    Wednesday, January 1, 2020 2:22 PM
  • Hi,

    Why not try replacing David's name with George?

    This loop goes through all the voice packs installed on your computer.

    foreach (var v in synthesizer.GetInstalledVoices().Select(v => v.VoiceInfo))
    {
        Console.WriteLine("Name:{0}, Gender:{1}, Age:{2}",
                          v.Description, v.Gender, v.Age);
    }

    Feel free to choose the sound you want, the previous reply is just an example.

    It should work.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 2, 2020 8:09 AM
  • Hi Riha,

    After a lot of testing on multiple computers, I found that the previous code was not 100% effective. On some computers, although many voice packs are installed, this code can only detect some of them, and I am not sure if this problem will occur on your computer.

    I'm not sure what caused this problem so far, this maybe a potential issue, but I will report it internally. 

    If there are new updates, I will let you know immediately.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 3, 2020 1:55 AM
  • Hi Timon,
    Thanks for the reply.

    private void say_George(string szovega)
            {
    
    
                SpVoice voice = new SpVoice();
                ISpVoice pVoice = (ISpVoice)voice;
    
                SpObjectTokenCategory otc = new SpObjectTokenCategory();
    
                otc.SetId("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices");
    
                ISpeechObjectTokens tokenEnum = otc.EnumerateTokens();
                int nTokenCount = tokenEnum.Count;
    
                foreach (ISpeechObjectToken sot in tokenEnum)
                {
    
                    {
                        pVoice.SetVoice((ISpObjectToken)sot);
                        try
                        {
    
                            pVoice.Speak(szovega, 0, out uint n);
                        }
                        catch (System.Exception)
                        {
                            Console.WriteLine("Cannot speak with the voice : {0}", sot.GetDescription());
                        }
                        Marshal.ReleaseComObject(sot);
                    }
                }
            }

    Maybe I described my problem badly.
    The problem is not George anymore, he is not alone.
    As you can see, there is a loop in my code, so a text is heard four times. This cycle should be replaced with a code that only George can speak.

    Best Regards,

    Riha


    Riha46


    • Edited by Riha46 Friday, January 3, 2020 10:05 AM
    Friday, January 3, 2020 10:05 AM
  • Hi Timon.

    That's how I choose Georg right now:

    foreach (ISpeechObjectToken sot in tokenEnum)
                {
                    if ((sot.GetDescription() == "Microsoft George - English (United Kingdom)"))
    
                    {
                        pVoice.SetVoice((ISpObjectToken)sot);
                        try
                        {
                            pVoice.Speak(szovega, 0, out uint n);
                        }
                        catch (System.Exception)
                        {
                            Console.WriteLine("Cannot speak with the voice : {0}", sot.GetDescription());
                        }
                        Marshal.ReleaseComObject(sot);
                    }
    
                }

    Of course it would be nicer without a loop.
    How would you do it?

    Best Regards,

    Riha


    Riha46


    Saturday, January 4, 2020 5:26 PM
  • Hi Riha,

    I'm glad to hear that you have solved the problem.

    I tested it. This API does not provide a method for selecting speech based on name, but we can use

    ISpeechObjectToken token = tokenEnum.Item (0); 

    to select a certain speech, but the problem is that in different computers, this index maybe different. So I think using foreach might be a better choice.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, January 6, 2020 6:21 AM