如何在语音识别 c# 中检测无效命令

本文关键字:检测 无效 命令 语音识别 | 更新日期: 2023-09-27 18:32:17

>我有一个问题。我正在用 c# 创建一个语音识别程序。我希望我的程序能够检测到不正确的命令。

我尝试

使用尝试和捕捉,但我认为我弄错了。

void Default_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        string speech = e.Result.Text;
        switch (case)...     
        {
              //Commands
        }  
    }
try
{
    if (speech != e.result.Text)
    Bill.Speak("You have given an invalid command. Please try again.");
}
catch{}

我怎样才能正确地做到这一点?

如何在语音识别 c# 中检测无效命令

只需为开关大小写添加默认值

  switch (speech)
  {
    case "1":
      Bill.Speak("Command 1");
      break;
    case "2":
      Bill.Speak("Command 2");
      break;
    default:
      Bill.Speak("You have given an invalid command. Please try again.");
      break;
   }

我认为您想要的是交换机的默认值。 所以

    switch (case)...     
    {
          //Commands
          default: // not recognized
            Bill.Speak("You have given an invalid command. Please try again.");
    }  

add 违约: Bill.Speak("我不懂命令");

到您的案例陈述