I am modifying Scott Hanselman's BabySmash code to support other languages.
- I installed the speech platform and a new language per these steps.
The language now shows up in the registry:
The language can now be selected and played by Windows:
System.Speech.Synthesis.SpeechSynthesizer.GetInstalledVoices()
now returns the voice.- 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);
I've tried upgrading to
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Speech.dll
.I've verified that the versions of
Microsoft.Speech.dll
and the language pack match.This code works for the default voices I've already had installed.
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.