【问题标题】:SpeechSynthesizer.SelectVoice() Fails with "No matching voice is installed or the voice was disabled"SpeechSynthesizer.SelectVoice() 失败并显示“未安装匹配的语音或语音已禁用”
【发布时间】:2016-01-13 20:38:54
【问题描述】:

我正在修改Scott HanselmanBabySmash 代码以支持其他语言。

  1. 我根据these steps 安装了语音平台和新语言。
  2. 该语言现在显示在注册表中:

  3. Windows 现在可以选择和播放语言了:

  4. System.Speech.Synthesis.SpeechSynthesizer.GetInstalledVoices() 现在返回声音。

  5. 但是下面代码中的SelectVoice() 会抛出错误“System.ArgumentException: 无法设置语音。未安装匹配的语音或语音被禁用。”
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. 我已经尝试升级到C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Speech.dll

  2. 我有 verified that the versionsMicrosoft.Speech.dll 和语言包匹配。

  3. 此代码适用于我已经安装的默认语音。

  4. 无奈之下,我什至尝试通过反射直接调用System.Speech.Internal.Synthesis.VoiceSynthesis.GetVoice(),但同样的错误。

如果您能提供任何帮助,我将不胜感激!谢谢。

【问题讨论】:

    标签: c# text-to-speech speechsynthesizer microsoft-speech-platform


    【解决方案1】:

    哈哈我觉得特别:this post on Python居然解决了我的问题:构建配置平台需要x64,而不是Any CPU

    【讨论】:

      【解决方案2】:

      另一种解决方案是安装 (x64) 位版本的 Microsoft Speech Platform SDK 和 Microsoft Server Speech Platform Runtime。我认为您已经安装了 (x86) 位并且平台尝试以 (x64) 位读取它。

      我和你有同样的问题,但恰恰相反,这对我有用!

      【讨论】:

        【解决方案3】:

        在我的情况下,我需要使用 Microsoft.Speech.Synthesis 而不是库 System.Speech.Synthesis。为此,我们需要转到 VisualStudio 上的解决方案资源管理器 --> 参考并浏览 Microsoft.Speech.dll

        using Microsoft.Speech.Synthesis;
        

        之后,您将拥有其他可用的运行时语言。

                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);
                }
        

        【讨论】:

        • Microsoft.Speech 看起来已被弃用。程序集不会在 Windows 10 上为我加载
        【解决方案4】:

        将用户身份更改为 Localsystem 解决了我的问题!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-01-31
          • 1970-01-01
          • 2023-03-11
          • 1970-01-01
          • 1970-01-01
          • 2020-01-19
          • 2018-02-23
          相关资源
          最近更新 更多