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: 

创建语音合成器的对象时不会发生错误,但在使用它时会发生错误。外汇。改变速率、音量等。

有没有人有解决这种问题的方法?解决方案?提示?有什么可以帮助解决这个烦人的问题吗?

4

1 回答 1

0

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

于 2013-04-17T10:03:01.097 回答