Unexpected error in speech recognition

Eduardo Gomez 3,416 Reputation points
2022-11-21T00:13:30.65+00:00

I worked with a friend on Saturday, and my code worked perfectly.

We were able to start recognition from a file and return the string to the ViewModel

List<char> Characers = new();

        StringBuilder builder = new();  

        var config = SpeechConfig.FromSubscription  
            (ConstantsHelpers.AZURE_KEY, ConstantsHelpers.AZURE_REGION);  

        //Configure speech recognition  

        var speechRecognizerWaiter = new TaskCompletionSource<string>();  

        using var audioConfig = AudioConfig.FromWavFileInput(FilePath);  
        if (!string.IsNullOrEmpty(FileName))  
        {  
            config.EnableDictation();  
            config.SpeechRecognitionLanguage = Lang;  

            using var speechRecognizer = new SpeechRecognizer(config, audioConfig);  

            speechRecognizer.Recognized += (sender, e) =>  
            {  
                if (e.Result.Reason == ResultReason.RecognizedSpeech)  
                {  
                    foreach (var item in e.Result.Text)  
                    {  
                        Characers.Add(item);  
                    }  
                }  
            };  

            speechRecognizer.SessionStarted += (sender, e) =>  
            {  

                Debug.WriteLine("-----------> started");  
            };  

            speechRecognizer.SessionStopped += (sender, e) =>  
            {  

                Debug.WriteLine("-----------> stooped");  

                foreach (var item in Characers)  
                {  
                    builder.Append(item);  
                }  

                Debug.WriteLine(builder.ToString());  

                speechRecognizerWaiter.SetResult(builder.ToString());  
            };  

            await speechRecognizer.StartContinuousRecognitionAsync();  

            var str = await speechRecognizerWaiter.Task;  

            await speechRecognizer.StopContinuousRecognitionAsync();  

            return str;  
        }  

        return null;  
    }  

Today I tried it and it is giving me some exceptions in the audioConfig

"Exception with an error code: 0x1 (SPXERR_UNINITIALIZED)"

audioConfig.AudioProcessingOptions = 'audioConfig.AudioProcessingOptions' threw an exception of type 'System.ApplicationException'

I tried to search on Google for any clue, and I read that I should update my Nugget Package. I tried to search for any update.

and I still have the same error

262318-image.png
262352-image.png

I am in the lastest

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,880 questions
{count} votes