Am enhancing en existing web application which makes the visually impaired people, to be used based on the Text to Speech & Speech Recognition
The same code is working fine in windows application, but not in web application.
If I put break point, it's coming to the point but the code is not getting execute.
Here is the code, please do the needful.
using System.Speech;
using System.Speech.Synthesis;
using System.Threading;
using System.Speech.Recognition;
SpeechSynthesizer ss = new SpeechSynthesizer();
PromptBuilder pb = new PromptBuilder();
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
SpeechRecognizer sr = new SpeechRecognizer();
protected void btn_Spk_Click(object sender, EventArgs e)
{
string optiona, optionb, optionc;
Choices clist = new Choices();
foreach (GridViewRow row in gvtemperament.Rows)
{
RadioButton rblist1 = ((RadioButton)row.FindControl("rdTemp_Opt1"));
RadioButton rblist2 = ((RadioButton)row.FindControl("rdTemp_Opt2"));
RadioButton rblist3 = ((RadioButton)row.FindControl("rdTemp_Opt3"));
Label lbl1 = (Label)row.FindControl("lbl_desc");
if (row.Cells[0].Text == "1")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText("Please answer all the Questions and you starts here!");
ss.Speak(pb);
Thread.Sleep(1500);
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "2")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "3")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "4")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "5")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "6")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "7")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "8")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "9")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
else if (row.Cells[0].Text == "10")
{
ss.SelectVoiceByHints(VoiceGender.Female);
ss.Volume = 100;
ss.Rate = -3;
pb.ClearContent();
pb.AppendText(lbl1.Text);
ss.Speak(pb);
Thread.Sleep(1500);
ss.SelectVoiceByHints(VoiceGender.Male);
pb.ClearContent();
pb.AppendText("Options are ");
ss.Speak(pb);
optiona = rblist1.Text;
optionb = rblist2.Text;
optionc = "Not Sure";
pb.ClearContent();
pb.AppendText(optiona);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionb);
ss.Speak(pb);
Thread.Sleep(700);
pb.ClearContent();
pb.AppendText(optionc);
ss.Speak(pb);
Thread.Sleep(150);
clist.Add(new string[] { "Yes", "No", "Not Sure" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=\"javascript\">" + "alert('Error');</script>");
}
}
}
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
foreach (GridViewRow row in gvtemperament.Rows)
{
RadioButton rblist1 = ((RadioButton)row.FindControl("rdTemp_Opt1"));
RadioButton rblist2 = ((RadioButton)row.FindControl("rdTemp_Opt2"));
RadioButton rblist3 = ((RadioButton)row.FindControl("rdTemp_Opt3"));
Label lbl1 = (Label)row.FindControl("lbl_desc");
if (row.Cells[0].Text == "1")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
rblist1.Text = "Narendran";
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
rblist1.Text = "Naren";
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
rblist1.Text = "Chk";
}
}
else if (row.Cells[0].Text == "2")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
rblist1.Text = "Round2";
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
rblist2.Text = "Round2";
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
rblist3.Text = "Round2";
}
}
else if (row.Cells[0].Text == "3")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else if (row.Cells[0].Text == "4")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else if (row.Cells[0].Text == "5")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else if (row.Cells[0].Text == "6")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else if (row.Cells[0].Text == "7")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else if (row.Cells[0].Text == "8")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else if (row.Cells[0].Text == "9")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else if (row.Cells[0].Text == "10")
{
if (e.Result.Text == "Yes")
{
rblist1.Checked = true;
}
else if (e.Result.Text == "No")
{
rblist2.Checked = true;
}
else //if (e.Result.Text == "Not Sure")
{
rblist3.Checked = true;
}
}
else
{
}
}
}Please do the needful.
Narendran Namachivayam.

Narendran N14 pointsPosted Jul 28, 2016, 8:22 PM EDT
Choices clist = new Choices(new string[] { "Yes", "No", "Not Sure" });This is the code working as of now, but at the end the page is keep on loading and nothing happened, hope once the page loaded ended the option button will be selected. Help me on this, why the page is keep on loading?