C# 异步使用语音执行命令
我们修改了论文,一位小组成员说,为了使我们的语音识别系统更好,我们需要添加一种处理命令的方法 例如,如果我给出一个默认命令C# 异步使用语音执行命令,c#,speech-recognition,C#,Speech Recognition,我们修改了论文,一位小组成员说,为了使我们的语音识别系统更好,我们需要添加一种处理命令的方法 例如,如果我给出一个默认命令 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.S
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.");
MSDN中的代码或多或少是正确的,您只是错过了已识别命令的处理程序,请参见完整示例:
如果不执行任何操作,程序可能会在SpeechRecognitor完成工作之前运行并终止。如果你能补充更多关于发生了什么的细节,那会很有帮助
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);
}