我在我的C#WPF项目中实现了一个TTS。C#SAPI可以说SSML字符串吗?
以前,我使用System.Speech.Synthesis命名空间中的TTS来说话。该讲话内容是SSML格式(语音合成标记语言,支持自定义语速,语音,强调)像以下:
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US"><prosody rate="x-fast">hello world. This is a long sentence speaking very fast!</prosody></speak>
但不幸的是System.Speech.Synthesis TTS有内存泄漏问题,因为我在问题Memory leak in .Net Speech.Synthesizer?中提到。
所以我决定使用SAPI COM组件。我可以轻松让SAPI发表纯文本内容。但是,我继续尝试让它说SSML字符串,我失败了。代码如下如下:
//Initialize TTS instance
SpeechLib.SpVoiceClass tts = new SpeechLib.SpVoiceClass();
//Generate SSML string
string textToSpeak = "hello world speak Extra Fast.";
PromptBuilder pb = new PromptBuilder();
pb.StartStyle(new PromptStyle(PromptRate.ExtraFast));
pb.AppendText(textToSpeak);
pb.EndStyle();
ssmlString = pb.ToXml(); //ssmlString = @"<speak version=""1.0"" ....
//Speak!
tts.Speak(ssmlString, SpeechLib.SpeechVoiceSpeakFlags.SVSFParseSsml);
代码的重要组成部分是
tts.Speak(ssmlString, SpeechLib.SpeechVoiceSpeakFlags.SVSFParseSsml);
它使用SpeechVoiceSpeakFlags enumerations指定TTS来讲行为。我尝试过几种标志的组合,但没有一个成功地说出SSML内容。
特别地,上面的代码也将提高以下例外:
System.Runtime.InteropServices.COMException了未处理
消息= “从HRESULT异常:0x80045003”
源= “Interop.SpeechLib”错误码= -2147201021堆栈跟踪: 在SpeechLib.SpVoiceClass.Speak(字符串文本,SpeechVoiceSpeakFlags旗) 在SpeechSynthesisMemLeakTest.Program.Test2()中d:\ PROJ \ TestSolutions \ CSharp_Quick_Apps \ SpeechSynthesisMemLeakTest \的Program.cs:线在SpeechSynthesisMemLeakTest.Program.Main(String [] args)位于Microsoft的System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args) D:\ Proj \ TestSolutions \ CSharp_Quick_Apps \ SpeechSynthesisMemLeakTest \ Program.cs中:行。 VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象状态) 在System.Threading.ThreadHelper.ThreadStart()的InnerException:
谁能告诉我如何正确使用标志来说出SSML内容?