[英]C# Speech Recognition Command Confirmation?
So I've made the application recognize what I say. 因此,我已使应用程序识别出我的意思。 But how do I make the application confirm a request when I command it to carry out a task? 但是,当我命令应用程序执行任务时,如何使应用程序确认请求?
As of now I have this code: 到目前为止,我有以下代码:
public partial class Form1 : Form
{
SpeechSynthesizer synth = new SpeechSynthesizer();
SpeechRecognitionEngine sRecognize= new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Choices sList = new Choices();
sList.Add(new String[] { "Exit"});
Grammar gr = new Grammar(new GrammarBuilder(sList));
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
sRecognize.SpeechRecognitionRejected += sRecognize_SpeechRecognitionRejected;
}
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "Exit")
{
Application.Exit();
}
}
}
So my question as an example: 以我的问题为例:
I say, " Exit" 我说,“ 退出”
Application confirms by: 申请通过以下方式确认:
Are you sure you want to exit? 你确定要离开?
And depending on my answer, the application responds. 然后根据我的回答,应用程序响应。
Yes being a confirmation and No being a request cancellation. 是是确认, 否是取消请求。 What changes do I have to make? 我必须进行哪些更改?
Something like this? 像这样吗
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "Exit")
{
Choices sList = new Choices();
sList.Add(new String[] { "Yes"});
Grammar gr = new Grammar(new GrammarBuilder(sList));
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += delegate(object sender, SpeechRecognizedEventArgs e)
{
Application.Exit();
};
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.