'Microsoft C++ exception: EEMessageException with Azure Cognitive Services

I wrote a program that uses the Azure (Cognitive Services) speech recognition system. The endire solution (Visual Studio 2019) is made by c# and vb.net projects.

The main solution is in vb .net

C# Script (addon):

using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using System;
using System.Threading.Tasks;

namespace WinLucyAddon.SpeechText
{
public class SpeechToText
{
    SpeechConfig speechConfig;
    AudioConfig audioConfig;
    SpeechRecognizer recognizer;
    SpeechSynthesizer synthesizer;
    string testo_restituito;

    public SpeechToText()
    {
        speechConfig = SpeechConfig.FromSubscription("xxxxxxxxxxxxxxxxxxxxxxxxx", "westeurope");
        this.speechConfig.SpeechRecognitionLanguage = "it-IT";
        this.speechConfig.SpeechSynthesisLanguage = "it-IT";
        this.speechConfig.EnableDictation();
        this.audioConfig = AudioConfig.FromDefaultMicrophoneInput();
        this.recognizer = new SpeechRecognizer(speechConfig, audioConfig);
        this.synthesizer = new SpeechSynthesizer(speechConfig);
        this.testo_restituito = "";
    }

    public void FromMic()
    {
        Console.Beep(1000, 300);

        var stopRecognition = new TaskCompletionSource<int>();

        this.recognizer.Recognizing += (s, e) =>
        {
            Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
        };
        this.recognizer.Recognized += (s, e) =>
        {
            if (e.Result.Reason == ResultReason.RecognizedSpeech)
            {
                Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                recognizer.StopContinuousRecognitionAsync();
                string substr = e.Result.Text.Substring(e.Result.Text.Length - 1);
                if (substr.Equals("."))
                {
                    this.testo_restituito = e.Result.Text.Remove(e.Result.Text.Length - 1, 1);
                }
                else this.testo_restituito = e.Result.Text;
            }
            else if (e.Result.Reason == ResultReason.NoMatch)
            {
                Console.WriteLine($"NOMATCH: Speech could not be recognized.");
            }
        };
        this.recognizer.Canceled += (s, e) =>
        {
            Console.WriteLine($"CANCELED: Reason={e.Reason}");

            if (e.Reason == CancellationReason.Error)
            {
                Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
                Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                Console.WriteLine($"CANCELED: Did you update the subscription info?");
            }

            stopRecognition.TrySetResult(0);
        };

        this.recognizer.SessionStopped += (s, e) =>
        {
            Console.WriteLine("\n    Session stopped event.");
            stopRecognition.TrySetResult(0);
        };


        this.recognizer.StartContinuousRecognitionAsync();

        Task.WaitAny(new[] { stopRecognition.Task });
    }

    public async Task<string> start_text_speech()
    {
            FromMic();
        return this.testo_restituito;
    }
}
}

This one is the vb .net method that calls c# function.

  Dim contenuto_ultimo_inserimento As String = " "    
  Private Async Function TextEditor_KeyUpAsync(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Tasks.Task Handles TextBox1.KeyUp

    'Funzione STT
    If (e.KeyCode = Keys.ControlKey) Then
        Dim vr As New voiceRecognition
        contenuto_ultimo_inserimento = Await (vr.stt_other_version(contenuto_ultimo_inserimento, TextBox1))
    End If

End Function

When I run it by Visual Studio 2019 it works without any problem, but when i publish it locally and i press the CTRL key (to call the c# script) it throws me this Exception:

Exception thrown at 0x76E3EC52 in WinLucy.exe: Microsoft C++ exception: EEMessageException at memory location 0x05CF9838.
Exception thrown at 0x76E3EC52 (KernelBase.dll) in WinLucy.exe: 0xE0434352 (parameters: 0x80131524, 0x00000000, 0x00000000, 0x00000000, 0x72AF0000).
Exception thrown at 0x76E3EC52 (KernelBase.dll) in WinLucy.exe: 0xE0434352 (parameters: 0x80131524, 0x00000000, 0x00000000, 0x00000000, 0x72AF0000).

Do you know any solution for this? Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source