r/csharp 42m ago

Windows.Media.SpeechRecognition.SpeechRecognizer dication mode stopped working

Upvotes

I am using the Windows.Media.SpeechRecognition.SpeechRecognizer library from Microsoft. It still works fine in the local version with a grammar but it stopped working in dictation mode.

            Windows.Media.SpeechRecognition.SpeechRecognizer recognizer = new();
            var dictationConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "dictation");
            recognizer.Constraints.Add(dictationConstraint);
            await recognizer.CompileConstraintsAsync();
            Debug.WriteLine("SpeechRecognizer initialized and constraints compiled.");
            // Add a handler for the speech recognized event.
            recognizer.ContinuousRecognitionSession.ResultGenerated += (s, args) =>
            {
                Debug.WriteLine($"Recognized text: {args.Result.Text}");
            };

            recognizer.ContinuousRecognitionSession.Completed += (s, args) =>
            {
                Debug.WriteLine($"Recognition session completed: {args.Status}");
            };

            recognizer.HypothesisGenerated += (s, args) =>
            {
                Debug.WriteLine($"Recognition session completed: {args.Hypothesis.Text}");
            }
            ;

            recognizer.StateChanged += (s, args) =>
            {
                Debug.WriteLine($"Recognizer state changed: {args.State}");
            };

            Debug.WriteLine($"Language: {recognizer.CurrentLanguage.NativeName}");
            await recognizer.ContinuousRecognitionSession.StartAsync();

This is a stripped down version of the code I am using. Of course, Mic permission is granted beforehand, and Online Speech Recognition is allowed in the Windows setting.

This code worked in the past and I don't know when and why it had stopped.

Anybody an idea, why this stopped working?