Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

c# - SpeechSynthesizer.SelectVoice() Fails with "No matching voice is installed or the voice was disabled"

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 AssembliesMicrosoftFramework.NETFrameworkv4.6.1System.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...