2

I am modifying Scott Hanselman's BabySmash code to support other languages.

  1. I installed the speech platform and a new language per these steps.
  2. The language now shows up in the registry:

    enter image description here

  3. The language can now be selected and played by Windows:

    enter image description here

  4. System.Speech.Synthesis.SpeechSynthesizer.GetInstalledVoices() now returns the voice.

  5. However SelectVoice() in the code below throws the error "System.ArgumentException: Cannot set voice. No matching voice is installed or the voice was disabled."
string phrase = null;
SpeechSynthesizer speech = new SpeechSynthesizer();
CultureInfo keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
InstalledVoice neededVoice = speech.GetInstalledVoices(keyboardCulture).FirstOrDefault();
if (neededVoice == null)
{
    phrase = "Unsupported Language";
}
else if (!neededVoice.Enabled)
{
    phrase = "Voice Disabled";
}
else
{
    speech.SelectVoice(neededVoice.VoiceInfo.Name);
}

speech.Speak(phrase);
  1. I've tried upgrading to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Speech.dll.

  2. I've verified that the versions of Microsoft.Speech.dll and the language pack match.

    enter image description here

  3. This code works for the default voices I've already had installed.

  4. In desperation, I've even tried invoking System.Speech.Internal.Synthesis.VoiceSynthesis.GetVoice() directly through reflection, but same exact error.

I would greatly appreciate any help you can provide! Thanks.

Community
  • 1
  • 1
kat
  • 577
  • 4
  • 7

5 Answers5

1

ha ha I feel special: this post on Python actually solved my problem: build configuration platform needs to be x64, not Any CPU!

Community
  • 1
  • 1
kat
  • 577
  • 4
  • 7
1

The problem is that some of the voices are not registered for all applications. There is a nice article about it here: https://www.ghacks.net/2018/08/11/unlock-all-windows-10-tts-voices-system-wide-to-get-more-of-them/

But for those who will find this answer when the above link doesn't work:

There are two registry keys which are involved.

  1. Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens
  2. Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens

The first one is used when querying with GetInstalledVoices() API call. The second one is used by the Windows Settings App.

To make the unlisted voices available for GetInstalledVoices() you need to copy the data of the desired voices from Speech_OneCore to the Speech node (and its x86 counterpart if needed).

  • Step 1: Open the Windows Registry Editor (regedit.exe)
  • Step 2: Open the list of available voices at Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
  • Step 3: Export the key of the voice you need
  • Step 4: Modify the exported Registry file and replace
    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\ with
    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\
  • Step 5: Also add both entries for 32 bit apps (if you need them) by duplicating the entries and replace the
    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\ with
    • HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Speech\Voices\Tokens\
  • Step 6: Import the modified file to the registry.

Now it should work (a restart might be needed)

morcibacsi
  • 43
  • 7
0

Another solution is to install (x64) bits version of Microsoft Speech Platform SDK and Microsoft Server Speech Platform Runtime. I think that you had installed (x86) bits of both and the plataform try to read it in (x64) bits.

I had the same problem that you but on the contrary and this works to me!

Rubén Aroca
  • 85
  • 1
  • 1
  • 7
0

In my case Instead of the library System.Speech.Synthesis i need to use Microsoft.Speech.Synthesis. For that we need to go to Solution Explorer on VisualStudio --> References and Browse for Microsoft.Speech.dll

using Microsoft.Speech.Synthesis;

After that you will have other Runtime Languages available.

        SpeechSynthesizer synth = new SpeechSynthesizer();    

        // Output information about all of the installed voices. 
        foreach (InstalledVoice voice in synth.GetInstalledVoices())
        {
            VoiceInfo info = voice.VoiceInfo;

            Console.WriteLine(" Name:          " + info.Name);
            Console.WriteLine(" Culture:       " + info.Culture);
            Console.WriteLine(" Age:           " + info.Age);
            Console.WriteLine(" Gender:        " + info.Gender);
            Console.WriteLine(" Description:   " + info.Description);
            Console.WriteLine(" ID:            " + info.Id);
        }
arainho
  • 35
  • 6
0

changing the user identity to Localsystem solve my problem ! enter image description here