多年来,我一直在不同的 PC 和不同版本的 Windows 上使用 Microsoft.Speech 合成器。我正在尝试在新的 Windows 10 PC 上设置开发和支持环境,但我无法让 spsynthesizer 正常工作。我现在已经下载了 Microsoft SDK5.1 和声音两次,以确保没有任何损坏。我已经使用调试器逐步完成了每一行代码,一切都按预期工作,直到调用 spsynthesizer.speak ......调用永远不会说话,也永远不会返回程序。我尝试以 x86、x64 和 AnyCPU 执行,并且我有一个 Microsoft.Speech 的参考条目。
有什么建议么?这是简单的 C# 测试应用程序。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Speech.Synthesis;
namespace test_text_to_speech
{
class Program
{
static void Main(string[] args)
{
Microsoft.Speech.Synthesis.SpeechSynthesizer spsynthesizer = new Microsoft.Speech.Synthesis.SpeechSynthesizer();
System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Speech.Synthesis.InstalledVoice> myvoices;
myvoices = spsynthesizer.GetInstalledVoices();
spsynthesizer.SelectVoice(myvoices[0].VoiceInfo.Name); //Invoke the one which you want
spsynthesizer.Volume = 100; // Can be 1 - 100
spsynthesizer.Rate = 1; // can be 1 - 10
spsynthesizer.SetOutputToDefaultAudioDevice();
PromptBuilder Thanks = new PromptBuilder();
Thanks.AppendSsmlMarkup("<voice xml:lang=\"en-US\">");
Thanks.StartStyle(new PromptStyle(PromptEmphasis.Strong));
Thanks.AppendText("Hello World");
Thanks.EndStyle();
Thanks.AppendSsmlMarkup("</voice>");
spsynthesizer.Speak(Thanks);
spsynthesizer.Speak("try with no markup");
}
}
}