Click here to Skip to main content
16,011,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I am using "System.Speech.Recognition" library of .Net framework in c#. As i am using few words in my grammar the recognition system recognizes different words as one of my added words in my grammar. I need to either decrease the flexibility of the recognition system or add a word as a wild card in my grammar.

Below is the code for adding few words and building grammar.

C#
SpeechRecognizer rec = new SpeechRecognizer();
rec.SpeechRecognized += rec_SpeechRecognized;
var c = new Choices();
            c.Add("Notepad");
            c.Add("Calculator");
            c.Add("Start");
            c.Add("excel");
            c.Add("word");
            c.Add("msWord");
            c.Add("ShutDown");
            c.Add("ControlPanel");
            c.Add("Paint");
            c.Add("commandPrompt");
            c.Add("myDocuments");
            var gb = new GrammarBuilder(c);
            var g = new Grammar(gb);
            rec.LoadGrammar(g);
            rec.Enabled = true;



Now the problem is that the recognizer recognizes a totally different word as one of the listed words in my grammar.
How is it possible to only recognize the given grammar words and ignore the rest?

Any help in this issue is appreciated.
TIA
Posted

1 solution

You cannot put a wild card in your grammar, of course. The recognition quality is not that bad (maybe, how you pronounce is a problem, I know from my experience (I have some accent, sometimes have to repeat things to get understood)). Now, you have only one grammar at a time (you should be able to switch grammars as you go from one mode to another in you application.

When the recognizer is running, it never recognizes any words beyond you current grammar. There can be three situation: correct positive recognition, failure to recognize and false positive. You can only detect failure to recognize:

C#
System.Speech.Recognition.SpeechRecognitionEngine engine =
   new System.Speech.Recognition.SpeechRecognitionEngine();
engine.SpeechRecognitionRejected += (source, eventInfo) => {
   LogList.Items.Add(
        @"What the hell are you trying to tell me?!
          Say it properly if you want to get served!");
} //engine.SpeechRecognitionRejected


You can also use System.Speech.Recognition.SpeechRecognitionEngine.SpeechDetected, System.Speech.RecognitionSpeechRecognitionEngine.SpeechHypothesized.

—SA
 
Share this answer
 
Comments
Abdullahomaid 10-Feb-11 23:19pm    
hi SAKryukov i implement your respectable idea but no effect came,now when i say some phrase from my library it is "recognize correct". but problem is that when i say something else or i say some phrase which
is not include in custom library that time also recognize one of custom library phrase. for "example i said wellcome myabe it recognize start" wellcome is not include in my library .how prevent that when i say phrase out of custom library then no phrase recognize from library . because wellcome is not in library .
wish you get my point.thank you
Sergey Alexandrovich Kryukov 11-Feb-11 23:17pm    
Not quite clear, could you post some more code?
You see, my sample is from my experimental code, it works fine (well pretty much, some false negative, less of false positive). I did not try much to test the system on "non-grammar" words, and perhaps recognition is not well designed to do that, it is intended to work with a person who honestly tries to speak out only what grammar ask to, e.t. commands. (Did I understand you correctly?).
--SA
Abdullahomaid 12-Feb-11 6:06am    
thank you SAKryukov,
this is the complete code:
problem:when i say something from the following grammar like(open Notepad,calculator...myDocuments)it is working .but when i say something out of those words that time also it give me out put one of the following grammar word.
using SpeechLib;
using IWshRuntimeLibrary;

namespace finalProject.Utils.Windows
{
public partial class Form1 : Form
{
SpeechRecognizer rec = new SpeechRecognizer();
public void Send(string keys, bool wait)
{
WshShell shell = new WshShellClass();
object wObj = wait;

shell.SendKeys(keys, ref wObj);
}
public void Send(string keys)
{
Send(keys, false);
}
public void SendWait(string keys)
{
Send(keys, true);
}
public Form1()
{
InitializeComponent();
rec.SpeechRecognized += rec_SpeechRecognized;
}

void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{

textBox1.Text = e.Result.Text;
}

private void Form1_Load(object sender, EventArgs e)
{
var c = new Choices();
c.Add("Open Notepad");
c.Add("Calculator");
c.Add("Start Menu");
c.Add("excel");
c.Add("Microsoft Word");
c.Add("msWord");
c.Add(" System ShutDown");
c.Add("ControlPanel");
c.Add("Paint Brush");
c.Add("command Prompt");
c.Add("my Documents");

var gb = new GrammarBuilder(c);

var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;

}

private void textBox1_TextChanged(object sender, EventArgs e)
{
string text = textBox1.Text.Trim();

switch (text)
{
case"Calculator":
System.Diagnostics.Process.Start("calc");
break;
case"Start Menu":
Send("^{ESC}");
break;
case"excel":
System.Diagnostics.Process.Start("excel");
break;
case "Open Notepad":
System.Diagnostics.Process.Start("notepad");
break;
case"Microsoft Word":
System.Diagnostics.Process.Start("winword");
break;
case"System ShutDown":
Send("%{F4}");
break;
case"ControlPanel":
System.Diagnostics.Process.Start("Control");
break;
case"Paint Brush":
System.Diagnostics.Process.Start("PBRUSH");
break;
case"command Prompt":
System.Diagnostics.Process.Start("cmd");
break;
case"my Documents":
System.Diagnostics.Process.Start("explorer");
break;
default:
textBox1.Text = "*";
return;

}
}
}
}
Sergey Alexandrovich Kryukov 12-Feb-11 14:38pm    
OK, thanks, I need to to look at this,
--SA
Abdullahomaid 13-Feb-11 0:20am    
ok i am waiting to your help or idea.
thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900