【发布时间】:2016-07-17 05:31:18
【问题描述】:
我有一个控制台应用程序,它具有使用 SAPI tts 引擎创建文件的功能:
<HandleProcessCorruptedStateExceptions> Function SpeechFile(Text As String, Folder As String, Voice As String) As String
Dim pth = Path.Combine(Folder, Text.GetHashCode & ".wav")
If Not File.Exists(pth) Then
Using synth = New SpeechSynthesizer
Dim fmt = New Speech.AudioFormat.SpeechAudioFormatInfo(8000, Speech.AudioFormat.AudioBitsPerSample.Eight, Speech.AudioFormat.AudioChannel.Mono)
synth.SetOutputToWaveFile(pth, fmt)
synth.SelectVoice(Voice)
Try
synth.Speak(Text)
Catch ex As Exception
ex.Data.Add("Path", pth)
ex.Data.Add("Text", Text)
Throw ex 'i have no idea why this err isnt logged normally
End Try
End Using
End If
Return pth
End Function
对Speak 的调用间歇性地失败并出现AccessViolationException。即使我添加了HandleProcessCorruptedStateExceptions 属性,并将调用包装在Try...Catch 中,此异常也会使整个控制台应用程序崩溃。因此,我无法记录崩溃或处理/关闭/重新启动。
我的第一个想法是引擎试图同时创建两个文件,但事实并非如此。
相关的 Windows 日志:
错误应用程序名称:MyConsole.exe,版本:1.0.0.0,时间 戳:0x56f8fd6e 错误模块名称:Moses64.dll,版本:0.0.0.0, 时间戳:0x510a6596 异常代码:0xc0000005 故障偏移量: 0x00000000000d03a1 错误进程 id: 0x1c10 错误应用程序 开始时间:0x01d188d7da12cb52 错误应用程序路径:C:\Program Files\MyConsole\MyConsole.exe 错误模块路径: C:\Program Files (x86)\Aharon\Hebrew Speech Synthesizer\Ron\Moses64.dll 报告 ID: 0a70f320-f519-11e5-80c3-d05099606348 故障包全名: 错误的包相关应用程序 ID:
应用程序:MyConsole.exe 框架版本:v4.0.30319 说明:进程因未处理的异常而终止。 异常信息:System.AccessViolationException 在 System.Speech.Synthesis.TtsEngine.ITtsEngine.Speak(System.Speech.Synthesis.TtsEngine.SPEAKFLAGS, System.Guid ByRef, IntPtr, IntPtr, IntPtr) 在 System.Speech.Internal.Synthesis.TtsProxySapi.Speak(System.Collections.Generic.List`1, 字节[])在 System.Speech.Internal.Synthesis.VoiceSynthesis.SpeakText(System.Speech.Internal.Synthesis.SpeakInfo, System.Speech.Synthesis.Prompt, System.Collections.Generic.List``1) 在 System.Speech.Internal.Synthesis.VoiceSynthesis.ThreadProc() 在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,布尔值)在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,布尔值)在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)在 System.Threading.ThreadHelper.ThreadStart()
我该如何处理这个异常,或者更好的是,防止它发生?
【问题讨论】:
-
从堆栈跟踪中应该有点明显,这个异常是在工作线程上引发的,而不是在 SpeechFile() 方法内。所以你无法抓住它。你需要让你的机器恢复健康。这需要什么是无法猜测的,它需要一个非托管调试器。避免第三者的声音,尝试另一台机器。
-
嗨。感谢您的输入。你能解释一下吗?如果这发生在外部进程的工作线程上,我的控制台怎么会崩溃?我不介意他们的引擎崩溃,但为什么它会降低我的控制台?不幸的是,我现在对引擎别无选择(由于许可和管理决策等)。我所需要的只是优雅地忽略他们的错误。谢谢!
-
谷歌“legacyUnhandledExceptionPolicy”。不要使用它。
-
嗨。我已经阅读了很多关于它的内容。当 tts 引擎抛出此类异常时,将其从我的
app.config中删除是否实际上使控制台能够继续运行?
标签: .net text-to-speech access-violation sapi