0

When using system.speech.synthesis like this:

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

I get this error:

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: 

The error doesn't occur when create an object of the speech synthesiser, but happens when using it. Fx. changing the rate, volume etc.

Does anyone have a solution for this kind of problem? Solution? Hints? Anything that can help solving this annoying problem?

Phu Minh Pham
  • 1,025
  • 7
  • 21
  • 38

1 Answers1

0

Just a guess, you are calling _speech.SpeakAsync(text); which means you are using the speech async, in the next line you dispose the _speech object by closing the using. I can imagine that can lead to problems. You should dispose _speech object after you have the result from the processing.

Peter
  • 27,590
  • 8
  • 64
  • 84