2

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

  1. 我按照这些步骤安装了语音平台和新语言。
  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. 我已经验证了版本Microsoft.Speech.dll语言包匹配。

    在此处输入图像描述

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

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

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

4

4 回答 4

1

哈哈我感觉很特别:这篇关于Python的帖子实际上解决了我的问题:构建配置平台需要x64,而不是Any CPU

于 2016-01-13T21:02:21.477 回答
0

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

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

于 2016-04-12T15:59:40.460 回答
0

将用户身份更改为 Localsystem 解决了我的问题! 在此处输入图像描述

于 2018-06-19T08:23:05.963 回答
0

在我的情况下,我需要使用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);
        }
于 2018-04-22T15:45:47.173 回答