I am having trouble in writing a code in my speech recognition engine. The task is, when the user says 'circle', the engine should automatically draw a circle on the form:
if(Speech == circle)
{
DrawCircle();
}
The code I'm using for speech recognition is...
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);
I don't know how to merge the above code to execute a circle when said so. Any related answer would be a great help!
e.Result.Text
will give you what the person said. So if you want to draw a circle when they say "circle"
:
if (e.Result.Text == "circle") {
//Draw a cricle
}