Asked By Prakhar
05-Sep-10 03:30 AM

//Here is the code for first page :-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SpeechRecognizer sp = new SpeechRecognizer();
Choices m = new Choices();
m.Add("next");
GrammarBuilder gb = new GrammarBuilder();
gb.Append(m);
Grammar g = new Grammar(gb);
sp.LoadGrammar(g);
sp.SpeechRecognized+=new EventHandler<SpeechRecognizedEventArgs>(sp_SpeechRecognized);
}
void sp_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "next")
{
button1.PerformClick();
}
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
}
//Here is code for next form :-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
SpeechRecognizer spr = new SpeechRecognizer();
Choices m = new Choices();
m.Add("back");
GrammarBuilder gb = new GrammarBuilder();
gb.Append(m);
Grammar g = new Grammar(gb);
spr.LoadGrammar(g);
spr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(spr_SpeechRecognized);
}
void spr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "back")
{
button1.PerformClick();
}
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.Show();
}
}
}
//But when we debug it, then it shows error as a exception. What is solution????