azure speech recognition crash the console-app on linux IOT

Zaeri 1 Reputation point
2020-08-11T16:14:44.69+00:00

hi there,
i have a console app that uses azure for speech recognition offline from microphone (by KeywordRecognitionModel table) on linux IOT(raspberry pi).

when i run it, at first time it works correctly and can recognize my word, but after 3 or more recognition , it crashes the app, even try-catch cant handle it.

Note : the following code works good on windows PC, without any crash or error, but on linux raspberry pi it crashes the app.

using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using System;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace VoiceAssistant
{
    class Program
    {

        static async Task Main()
        {
        bool working = false;
            while (true)
            {
                try
                {
                    if (!working)
                    {
                        Console.WriteLine("**true working**");

                        working = true;
                        await PropertyStart();
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine("**false working**");

                    working = false;
                    Console.WriteLine(ex.Message);

                    Console.ReadLine();

                }
            }

        }

        private static async Task PropertyStart()
        {
            int count = 0;

            Console.WriteLine("Start 2");
            try
            {
                //var config = SpeechTranslationConfig.FromSubscription("key", "westus");

                Console.WriteLine("Step 1");


                //RecordingPanel recordingPanel = new RecordingPanel();

                var keywordModel = KeywordRecognitionModel.FromFile("my_home.table");

                Console.WriteLine("Step 2");



                var audioConfig = AudioConfig.FromDefaultMicrophoneInput();

                var keywordRecognizer = new KeywordRecognizer(audioConfig);
                //keywordRecognizer.Properties.SetProperty("SPEECH-ObjectCountWarnThreshold", "10000");

                Console.WriteLine("Step 3");




                while (true)
                {


                    try
                    {

                        Console.WriteLine("Start Result");



                        KeywordRecognitionResult result = await keywordRecognizer.RecognizeOnceAsync(keywordModel);


                        Console.WriteLine("A Start Result");

                        // Checks result.
                        if (result.Reason == ResultReason.RecognizedKeyword)
                        {
                            count++;

                            Console.WriteLine("Stop");

                            //await keywordRecognizer.StopRecognitionAsync();

                            //await keywordRecognizer.StopRecognitionAsync();
                            Console.WriteLine("a Stop" + result.Duration.TotalSeconds.ToString());


                            Console.WriteLine(count.ToString() + $"We recognized: {result.Text}");
                            //recordingPanel.StartBtn_Click();
                            //keywordRecognizer.Dispose();


                        }
                        else if (result.Reason == ResultReason.NoMatch)
                        {
                            Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                        }
                        else if (result.Reason == ResultReason.Canceled)
                        {
                            var cancellation = CancellationDetails.FromResult(result);
                            Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                            if (cancellation.Reason == CancellationReason.Error)
                            {
                                Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                                Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                                Console.WriteLine($"CANCELED: Did you update the subscription info?");
                            }
                        }
                        //await RecognizeSpeechAsync();
                        Console.WriteLine("**");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error in :::: " + ex.Message);
                    }

                }

            }
            catch (Exception ex)
            {

                Console.WriteLine("Error " + ex.Message);

            }
            Console.ReadLine();
        }



}
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,765 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
222 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Zaeri 1 Reputation point
    2020-08-14T14:50:38.493+00:00

    After many tests, I was convinced that the problem is with KeywordRecognizer !

    we need help from Microsoft team for fixed this bug


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.