system.speech.synthesis中的访问冲突异常

时间:2013-04-17 09:56:58

标签: c# wpf speech speech-synthesis

使用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。改变率,音量等。

有没有人能解决这类问题?解?提示?什么能帮助解决这个恼人的问题?

1 个答案:

答案 0 :(得分:0)

只是一个猜测,你正在调用_speech.SpeakAsync(text);这意味着你正在使用语音异步,在下一行中你通过关闭使用来处理_speech对象。我可以想象这会导致问题。在获得处理结果后,应该处理_speech对象。