locked
[UWP] ПРоблема с SpeechRecognizer. Некорректное распознавание речиОдн RRS feed

  • Общие обсуждения

  • Столкнулся с проблемой некорректной работы SpeechRecognizer в своём приложении. Пользователю доступно только две команды: "Next" и "Back". Однако довольно часто команда "Next" распознаётся как "Back". В чём может быть проблема? Код прилагается.

    public sealed class Grid
        {
            private SpeechRecognizer _speechRecognizer;
            private CoreDispatcher _coreDispatcher;
            private ResourceMap _speechResourceMap;
    
            public Grid()
            {
               
                InitializeRecognizer();
            }
    
            private async void InitializeRecognizer()
            {
                var defaultLanguage = SpeechRecognizer.SystemSpeechLanguage;
                _speechRecognizer = new SpeechRecognizer(defaultLanguage);
                _coreDispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
                _speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("VoiceCommands");
                
                var speechContext = ResourceContext.GetForCurrentView();
                speechContext.Languages = new[] { defaultLanguage.LanguageTag };
                _speechRecognizer.Constraints.Add(
                    new SpeechRecognitionListConstraint(
                        new List<string>()
                        {
                            _speechResourceMap.GetValue("Next",speechContext).ValueAsString,
    _speechResourceMap.GetValue("Back", speechContext).ValueAsString
     }));
                
         var result = await _speechRecognizer.CompileConstraintsAsync();
                if (result.Status == SpeechRecognitionResultStatus.Success)
                {
                    _speechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;
                    _speechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
                    
                    await _speechRecognizer.ContinuousRecognitionSession.StartAsync();
                    
                }
            }
    
                   
            private async void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, 
                SpeechContinuousRecognitionResultGeneratedEventArgs args)
            {
                if (args.Result.Confidence == SpeechRecognitionConfidence.Medium ||
                    args.Result.Confidence == SpeechRecognitionConfidence.High)
                {
                    await _coreDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                    {
                        string command = args.Result.Text;
                        double conf = Math.Round(args.Result.RawConfidence, 2);
                        switch (args.Result.Constraint.Tag)
                        {
                            case "Next":
                                SetHorizontalOffset(-ItemsPanelRoot.ActualWidth);
                                break;
                            case "Back":
                                SetHorizontalOffset(ItemsPanelRoot.ActualWidth);
                                break;
                        }
                    });
                }
            }
        }

    29 ноября 2015 г. 18:02