2015-02-07 39 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); 
}