C#UWP SpeechRecognizer问题

时间:2015-11-27 22:38:50

标签: c# speech-recognition uwp

我正在开发UWP并希望使用SpeechRecognizer。它应该只对词语做出反应" Next"和"返回"。但通常,它会识别" NExt" as"返回"。我的代码如下。怎么解决这个问题?

var defaultLanguage = SpeechRecognizer.SystemSpeechLanguage;
        _speechRecognizer = new SpeechRecognizer(defaultLanguage);
        _coreDispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
        var constraintList = new SpeechRecognitionListConstraint(new List<string>() { "Next", "Back" });
        _speechRecognizer.Constraints.Add(constraintList);

        var result = await _speechRecognizer.CompileConstraintsAsync();
        if (result.Status == SpeechRecognitionResultStatus.Success)
        {
            _speechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;
            _speechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
            await _speechRecognizer.ContinuousRecognitionSession.StartAsync();
        }

这是ResultGeneratedEvent:

private async void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
    {
        {
            await _coreDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {

                string command = args.Result.Text;
                Messenger.Default.Send(new VoiceReactMessage(command));
                switch (command)
                {
                    case "Next":
                        SetHorizontalOffset(-ItemsPanelRoot.ActualWidth);
                        break;
                    case "Back":
                        SetHorizontalOffset(ItemsPanelRoot.ActualWidth);
                        break;
                }
            });
        }

1 个答案:

答案 0 :(得分:4)

不幸的是,你已经遇到了使用语音识别的困难,有时它无法准确识别你所说的内容。

我建议的一件事就是利用你得到的Confidence level作为结果的一部分。使用置信度,您可以决定是否要接受结果或尝试要求用户重复他们所说的内容。