2016-03-29 102 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本身還不足以

感謝你的幫助!

相關問題