none
Why isn't my program detecting all TTS voices? RRS feed

  • Question

  • When this code runs in my program:

    public static SpeechLib.SpVoice SP = new SpVoice();

    foreach (SpeechLib.ISpeechObjectToken v in SP.GetVoices())
                {
                    comboBoxVoice.Items.Add(v.GetDescription(49));
                }

    Only Zira, Hazel, and David are detected, while I have many others and also in other than English in Edge TTS.

    Why

    • Edited by Tam1988 Monday, April 1, 2019 1:25 AM
    Monday, April 1, 2019 1:24 AM

Answers

  • Well thx, but the code in the links provided is in VB, I need in C# please...

    It is about the same code in C# as in VB....

    For example, for the second registry key :

    SpVoice voice = new SpVoice();
    SpObjectTokenCategory otc = new SpObjectTokenCategory();
    // otc.SetId("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices");
    otc.SetId("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices");
    ISpeechObjectTokens tokenEnum = otc.EnumerateTokens();
    int nTokenCount = tokenEnum.Count;
    Console.WriteLine("Number of voices: {0}", nTokenCount);
    foreach (ISpeechObjectToken sot in tokenEnum)
    {
        Console.WriteLine("Voice : {0}", sot.GetDescription());
        //if ((sot.GetDescription() == "Microsoft Julie - French (France)"))
        {
            voice.Voice = (SpObjectToken)sot;
            try
            {
                voice.Speak("Hello! This is a test");
            }
            catch (System.Exception ex)
            {                       
                Console.WriteLine("Cannot speak with the voice : {0}", sot.GetDescription());
            }                    
            Marshal.ReleaseComObject(sot);
        }
    }




    Wednesday, April 3, 2019 9:41 PM

All replies

  • Hi

    Thank you for posting here.

    Based on your description, you want to detect all tts services in your code.
    After searching it, I found it is related to your registry. The relevant key is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens. Underneath, you'll find the installed voices.

    Test Result:

    Registry:

    Best Regards,

    Jack


    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.



    Tuesday, April 2, 2019 1:59 AM
    Moderator
  • I want them in a combobox, and when the user presses Ctrl+C twice my program speaks the text in clipboard in the voice selected, it works perfectly but not with all voices, someone told me long ago that it may be an issue of 32 and 64 bit compatibility that my program isn't detecting all voices, I want the program to work on any new Windows computer it gets installed on...
    Tuesday, April 2, 2019 6:29 PM
  • You get the voices from 

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices

    and

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices

    (WOW6432Node if 32-bit on 64-bit)

    with

    SpObjectTokenCategory.SetId

    and

    SpObjectTokenCategory.EnumerateTokens


    Wednesday, April 3, 2019 9:35 AM
  • How do I use the voices to speak text with them, it doesn't detect all voices as I said, this is what I use, what should I replace it with?

    public static SpeechLib.SpVoice SP = new SpVoice();

    foreach (SpeechLib.ISpeechObjectToken v in SP.GetVoices())
                {
                    comboBoxVoice.Items.Add(v.GetDescription(49));
                }

    Wednesday, April 3, 2019 6:55 PM
  • As I said, with

    SpObjectTokenCategory.SetId

    and

    SpObjectTokenCategory.EnumerateTokens

    with the 2 registry keys for SetId, instead of  SP.GetVoices()

    (tested on Windows 10, I get all the voices)

    Wednesday, April 3, 2019 7:38 PM
  • Well thx, but the code in the links provided is in VB, I need in C# please...
    Wednesday, April 3, 2019 8:48 PM
  • Well thx, but the code in the links provided is in VB, I need in C# please...

    It is about the same code in C# as in VB....

    For example, for the second registry key :

    SpVoice voice = new SpVoice();
    SpObjectTokenCategory otc = new SpObjectTokenCategory();
    // otc.SetId("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices");
    otc.SetId("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices");
    ISpeechObjectTokens tokenEnum = otc.EnumerateTokens();
    int nTokenCount = tokenEnum.Count;
    Console.WriteLine("Number of voices: {0}", nTokenCount);
    foreach (ISpeechObjectToken sot in tokenEnum)
    {
        Console.WriteLine("Voice : {0}", sot.GetDescription());
        //if ((sot.GetDescription() == "Microsoft Julie - French (France)"))
        {
            voice.Voice = (SpObjectToken)sot;
            try
            {
                voice.Speak("Hello! This is a test");
            }
            catch (System.Exception ex)
            {                       
                Console.WriteLine("Cannot speak with the voice : {0}", sot.GetDescription());
            }                    
            Marshal.ReleaseComObject(sot);
        }
    }




    Wednesday, April 3, 2019 9:41 PM
  • Castorix, you're invited to become an Answerer: https://social.msdn.microsoft.com/Forums/vstudio/en-US/2867fff5-a57e-4413-b1b0-25208a3cfa74/adding-answerers-and-moderators-to-this-forum?forum=csharpgeneral

    Ed Price, Azure Development Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Wednesday, April 3, 2019 9:54 PM
    Owner
  • THAAAANKS YOU ARE AWESOME!!!

    WORKS LIKE MAGIC!!!

    Should I do it it for both the HKEY and delete the duplicates? the second one showed me all 8 voices in in my machine...

    Wednesday, April 3, 2019 10:33 PM
  • Hi

    It seems that your problem has been solved. If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Jack


    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, April 11, 2019 6:35 AM
    Moderator