2015-02-07 68 views
0

我们已经进行了论文修改,一位小组成员表示,为了使我们的语音识别系统更好,我们增加了一种处理指令的方法。异步执行语音指令

例如,如果我给一个默认命令

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

我希望系统能够告诉该命令仍在处理之前,用户可以给另一个命令的用户。就像:

//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."); 
+0

不做任何事情,也许程序运行并在speechRecognizer完成工作之前终止。如果您可以在发生的事情上添加更多细节,那会很有帮助 – 2015-02-07 00:49:44

回答

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); 
}