如何在C#中使用语音作为命令?

如何在C#中使用语音作为命令?,c#,.net,speech-recognition,voice,voice-recognition,C#,.net,Speech Recognition,Voice,Voice Recognition,我在语音识别引擎中编写代码时遇到问题。 任务是,当用户说“圆圈”时,引擎应自动在表单上画一个圆圈: if(Speech == circle) { DrawCircle(); } 我用于语音识别的代码是 namespace speechexampl { public partial class Form1 : Form { SpeechRecognizer rec = new SpeechRecognizer(); public For

我在语音识别引擎中编写代码时遇到问题。 任务是,当用户说“圆圈”时,引擎应自动在表单上画一个圆圈:

if(Speech == circle)
{
    DrawCircle();
}
我用于语音识别的代码是

namespace speechexampl
{
    public partial class Form1 : Form
    {

        SpeechRecognizer rec = new SpeechRecognizer();

        public Form1()
        {

            InitializeComponent();

            rec.SpeechRecognized += rec_SpeechRecognized;

        }


        void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            lblLetter.Text = e.Result.Text;
        }

        void Form1_Load(object sender, EventArgs e)
        {

             var c = new Choices();
             for (var i = 0; i <= 100; i++)

             c.Add(i.ToString());

             var gb = new GrammarBuilder(c);

             var g = new Grammar(gb);

             rec.LoadGrammar(g);

             rec.Enabled = true;

         }
     }
}

//**

//> and to draw circle or rectangle:

//**

Pen myPen2 = new Pen(System.Drawing.Color.Red, 3);
Rectangle myRectangle2 = new Rectangle(95, 130, 100, 100);
graphicsObj.DrawEllipse(myPen2, myRectangle2);
namespace speechexampl
{
公共部分类Form1:Form
{
SpeechRecognizer rec=新的SpeechRecognizer();
公共表格1()
{
初始化组件();
rec.speechrecogned+=rec_speechrecogned;
}
void rec_SpeechRecognized(对象发送方,SpeechRecognizedEventArgs e)
{
lblLetter.Text=e.Result.Text;
}
void Form1\u加载(对象发送方,事件参数e)
{
var c=新选择();
对于(var i=0;i)和绘制圆或矩形:
//**
钢笔myPen2=新钢笔(System.Drawing.Color.Red,3);
矩形myRectangle2=新矩形(95130100100);
画法抽屉(myPen2,myRectangle2);

我不知道如何合并上面的代码来执行一个圆圈。任何相关的答案都会非常有帮助!

e.Result.Text
会告诉你这个人说了什么。所以如果你想在他们说
“圆圈”
时画一个圆圈:


请正确设置代码格式。您的
rec_speechrecogned
事件处理程序与圆圈没有任何关系。您需要检查“圆圈”以及对
DrawCircle()
的相应调用…到“-1”-点击器:请告诉他您为什么单击“-1”,他是新来的!我不知道这门课-但是做
e.Result.Text.ToLower()
更安全吗?是的,我只是没说。)我相信他们会明白的:)@annonymously….天哪,它成功了…我从过去三天开始就很紧张,因为这行代码:)非常非常感谢你的帮助,我会永远记得,你把我带出了地狱:)谢谢
if (e.Result.Text == "circle") {
    //Draw a cricle
}