异步执行带语音的命令

时间:2015-02-07 00:12:33

标签: c# speech-recognition

我们对论文进行了修订,一位小组成员说,为了使我们的语音识别系统更好,就是增加一种处理命令的方法。

例如,如果我提供默认命令

case "What time is it?":
WVASRS.Speak("time");
break;

我希望系统能够在用户提供另一个命令之前告诉用户COMMAND仍在处理。类似的东西:

//I will give a command while the the other command is processing
case "What day is it":
WVASRS.Speak("day");
break;

WVASRS.Speak("Another command is still processing. Please Wait for a few seconds before you can give another command.");

好吧,如果在MSDN上找到了什么,但它什么也没做。这是片段:

    // Assign input to the recognizer and start asynchronous
    // recognition.
    recognizer.SetInputToDefaultAudioDevice();

    completed = false;
    Console.WriteLine("Starting asynchronous recognition...");
    recognizer.RecognizeAsync(RecognizeMode.Multiple);

    // Wait 30 seconds, and then cancel asynchronous recognition.
    Thread.Sleep(TimeSpan.FromSeconds(30));
    recognizer.RecognizeAsyncCancel();

    // Wait for the operation to complete.
    while (!completed)
    {
      Thread.Sleep(333);
    }
    Console.WriteLine("Done.");

1 个答案:

答案 0 :(得分:0)

来自MSDN的代码或多或少是正确的,您只是错过了已识别命令的处理程序,请参阅完整示例here

 recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

以后

// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{

  if (actionRunning) {
      speak("Busy");
  }
  if (e.Result.Text.Equals("what is the time")) {
      actionRunning = true;
      startAction() 
  }
  Console.WriteLine("Speech recognized: " + e.Result.Text);
}