2016-03-29 101 views
0

我有了创建使用SAPI TTS引擎文件功能的控制台应用程序:AccessViolationException在SAPI崩溃我的控制台

<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异常代码:0000005故障偏移: 0x00000000000d03a1出错进程ID:0x1c10错误的应用程序 开始时间:0x01d188d7da12cb52错误的应用程序路径:C:\ PROGRAM 文件\ MyConsole \ MyConsole.exe错误模块路径: C:\ Program Files文件(x86)的\阿哈\希伯来语讲话 合成\罗恩\ Moses64.dll报告编号: 0a70f320-f519-11e5-80c3-d05099606348断裂作用封装的全名: 断裂作用包相对应用程序ID:

应用程序:MyConsole.exe Framework版本: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, Byte [])at 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, 系统.Threading.ContextCallback,Syst在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean)在 System.Threading.ExecutionContext.Run , System.Threading.ContextCallback,System.Object的)在 System.Threading.ThreadHelper.ThreadStart()


我如何处理这个异常,或者更好的,防止它的发生?

+0

从堆栈跟踪中可以看出,该异常在工作线程上抛出,而不在SpeechFile()方法内。所以你不能抓住它。你需要让你的机器再次健康。所需要的是无法猜测的,它需要一个非托管调试器。避免第三方声音,尝试另一台机器。 –

+0

嗨。感谢您的输入。你能解释一下吗?如果这发生在外部进程上的工作线程上,那么我的控制台如何崩溃?我不介意他们的引擎崩溃,但为什么它会把我的控制台降下来呢?不幸的是,我现在没有选择引擎(由于许可和管理决策等)。我需要的只是优雅地忽略他们的错误。谢谢! –

+0

Google“legacyUnhandledExceptionPolicy”。不要使用它。 –

回答

-1

最后这是因为我错过了legacyUnhandledExceptionPolicyapp.config。(由于某种原因,我已经放错了地方到一个错误的文件)

一旦我把它添加到我的app.config异常被越来越处理非常漂亮

似乎HandleProcessCorruptedStateExceptions本身还不足以

感谢你的帮助!

相关问题