๐Ÿ”’ Closed Help speech recognition

Status
Not open for further replies.

DavidPhilip

Enthusiast
Help po,, wla naman pong error sa code pero may prompt na ganito pag nag run

Code:

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;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;


namespace trylng
{
public partial class Form1 : Form
{
SpeechSynthesizer ss = new SpeechSynthesizer();
PromptBuilder pb= new PromptBuilder();
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
Choices clist;
public Form1()
{



InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{

button1.Enabled = false;
button2.Enabled = true;
clist.Add(new string[]{"hello","how are you","what is the current time","open chrome","thank you","close"});

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)
{
MessageBox.Show(ex.Message, "ERROR");

}
}

void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.ToString())
{
case "hello":
ss.SpeakAsync("hello david");
break;
case "how are you":
ss.SpeakAsync("i am okay");
break;
case "what is the current time":
ss.SpeakAsync("current time is " + DateTime.Now.ToLongTimeString());
break;
case "thank you":
ss.SpeakAsync("your welcome");
break;


}

textBox1.Text += e.Result.ToString() + Environment.NewLine;

}

private void button2_Click(object sender, EventArgs e)
{
sre.RecognizeAsyncStop();
button1.Enabled = true;
button2.Enabled = false;
}

}
}



error daw.webp
 
May error yata sa code.

Up natin para may makatulong sayo sir
 
Disclaimer: I don't know C#
May error ka sa
Code:
private void button1_Click(object sender, EventArgs e)
{

button1.Enabled = false;
button2.Enabled = true;
clist.Add(new string[]{"hello","how are you","what is the current time","open chrome","thank you","close"});

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)
{
MessageBox.Show(ex.Message, "ERROR");

}
}
After inspection may try-catch ka, which means outside the try catch yung error. NullPointerException yung error so it means na it's about a referenced object na walang instance.

After further inspection you called
Code:
clist.Add(new string[]{"hello","how are you","what is the current time","open chrome","thank you","close"});
pero wala naman sa code mo na nag create ka ng Choices instance. Try mo mag clist = new Choices(); or whatever, kung pano man siya sa C#, then show the full error kung hindi pa rin nag run
 
Disclaimer: I don't know C#
May error ka sa
Code:
private void button1_Click(object sender, EventArgs e)
{

button1.Enabled = false;
button2.Enabled = true;
clist.Add(new string[]{"hello","how are you","what is the current time","open chrome","thank you","close"});

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)
{
MessageBox.Show(ex.Message, "ERROR");

}
}
After inspection may try-catch ka, which means outside the try catch yung error. NullPointerException yung error so it means na it's about a referenced object na walang instance.

After further inspection you called
Code:
clist.Add(new string[]{"hello","how are you","what is the current time","open chrome","thank you","close"});
pero wala naman sa code mo na nag create ka ng Choices instance. Try mo mag clist = new Choices(); or whatever, kung pano man siya sa C#, then show the full error kung hindi pa rin nag run
Thanks po oks na,, problema ko nalang po is ung accuracy
 
Status
Not open for further replies.

About this Thread

  • 5
    Replies
  • 964
    Views
  • 4
    Participants
Last reply from:
DavidPhilip

Trending Topics

Online now

Members online
1,010
Guests online
1,298
Total visitors
2,308

Forum statistics

Threads
2,274,204
Posts
28,954,236
Members
1,234,144
Latest member
frondalauro1
Back
Top