0

When trying to use SpeechSynthesizer from the Microsoft.CognitiveServices.Speech sdk, I noticed that Dispose() hangs if it gets called after StopSpeakingAsync has been called.

Is there a way to circumvent this? I did a short console app that illustrates the problem below. I used Reflector to try to understand what was going on inside the library but only found out that it seems to be SpxExceptionThrower.LogErrorIfFail that hangs.

I'm using version 1.18.0 of the sdk.

(Note that it is necessary to have a Cognitive Services/Speech Services subscription and enter the key and region into the .FromSubscription call)

Thanks!

static async Task Main(string[] args)
{
    var config = SpeechConfig.FromSubscription("your-own-subscription-key", "your-region");
    var synthesizer = new SpeechSynthesizer(config);
    var task = synthesizer.SpeakTextAsync("Some long speech that keeps going on forever and ever and ever...");
    task.Wait(2000);
    await synthesizer.StopSpeakingAsync();
    synthesizer.Dispose();
    Console.WriteLine("This line will never be reached");
}

// Microsoft.CognitiveServices.Speech.Internal.InteropSafeHandle

protected override bool ReleaseHandle()
{
   if (this.releaseHandleFunc != null)
   {
      // LogErrorIfFail appears to hang
      SpxExceptionThrower.LogErrorIfFail(this.releaseHandleFunc(base.handle));
      this.releaseHandleFunc = null;
      base.handle = IntPtr.Zero;
   }
   return true;
}
  • Hi, I am an engineer working on the SDK. Could you tell me the SDK you are using? And maybe you can share me the [log](https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/how-to-use-loggin) – Yulin Li Aug 07 '21 at 02:49
  • Hi! Sure, I'm using the latest stable version: 1.18.0. The log file is [here](https://pastebin.com/PZcVE1Nb). – Martin Kallner Aug 08 '21 at 10:50
  • OK thanks! Seems this is a bug, and we will look into it. As a workaround, you can wait `StopSpeakingAsync()` finished (not using `await`) before disposing the synthesizer. – Yulin Li Aug 09 '21 at 02:31

0 Answers0