2013-04-17 133 views
0

當使用system.speech.synthesis這樣的:訪問衝突異常

using (_speech) 
{ 
    _speech.SelectVoice("Anne"); 
    _speech.SpeakCompleted += OnSpeakCompleted; 
    _speech.Rate = Convert.ToInt32(Rate); 
    _speech.Volume = Convert.ToInt32(Volume); 
    _speech.SpeakAsync(text); 
} 

我得到這個錯誤:

System.AccessViolationException was unhandled 
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 
Source=System.Speech 
StackTrace: 
     at System.Speech.Internal.ObjectTokens.ObjectToken.ISpObjectWithToken.SetObjectToken(ISpObjectToken pToken) 
     at System.Speech.Internal.ObjectTokens.ObjectToken.CreateObjectFromToken[T](String name) 
     at System.Speech.Internal.Synthesis.VoiceSynthesis.GetComEngine(VoiceInfo voiceInfo) 
     at System.Speech.Internal.Synthesis.VoiceSynthesis.GetProxyEngine(VoiceInfo voiceInfo) 
     at System.Speech.Internal.Synthesis.VoiceSynthesis.ThreadProc() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.runTryCode(Object userData) 
     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
InnerException: 

當創建一個不發生錯誤語音合成器的對象,但使用它時發生。 FX。改變費率,數量等

有沒有人有這種問題的解決方案?解?提示?有什麼可以幫助解決這個惱人的問題?

+0

嗨,你解決了這個問題嗎? – Yuki

回答

0

只是一個猜測,你打電話給_speech.SpeakAsync(文本);這意味着您正在使用語音異步,在下一行中通過關閉使用來處理_speech對象。我可以想象這會導致問題。處理結果後,應該拋棄_speech對象。

+0

我剛剛嘗試刪除使用,但它給了我同樣的錯誤 –