المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Speech Recognition



C# Programming
01-31-2010, 01:11 AM
Hello,
I want to build an application for writing text in textbox using speech recognition. i.e. if i speak "This is my first application" it should be displayed on textbox.
I have tried but failed. Here is my code.

System.Speech.Recognition.SpeechRecognitionEngine recognizer;
private void Form3_Load(object sender, EventArgs e)
{
recognizer = new System.Speech.Recognition.SpeechRecognitionEngine();

GrammarBuilder dictaphoneGB = new GrammarBuilder();
GrammarBuilder dictation = new GrammarBuilder();
dictation.AppendDictation();
dictaphoneGB.Append(new SemanticResultKey("StartDictation", new SemanticResultValue("Start Dictation", true)));
dictaphoneGB.Append(new SemanticResultKey("DictationInput", dictation));
dictaphoneGB.Append(new SemanticResultKey("EndDictation", new SemanticResultValue("Stop Dictation", false)));
GrammarBuilder spelling = new GrammarBuilder();
spelling.AppendDictation("spelling");
GrammarBuilder spellingGB = new GrammarBuilder();
spellingGB.Append(new SemanticResultKey("StartSpelling", new SemanticResultValue("Start Spelling", true)));
spellingGB.Append(new SemanticResultKey("spellingInput", spelling));
spellingGB.Append(new SemanticResultKey("StopSpelling", new SemanticResultValue("Stop Spelling", true)));
GrammarBuilder both = GrammarBuilder.Add(dictaphoneGB, spellingGB);
Grammar grammar = new Grammar(both);
grammar.Enabled = true;
grammar.Name = "Dictaphone and Spelling ";
recognizer.LoadGrammar(grammar);

recognizer.SetInputToDefaultAudioDevice();
recognizer.RecognizeAsync(RecognizeMode.Multiple);
recognizer.SpeechRecognized += OnSpeechRecognized;
}

private void OnSpeechRecognized(object sender, System.Speech.Recognition.SpeechRecognizedEventArgs e)
{
textBox1.Text = e.Result.Text;
}


There is no output.
Please help me i am new to speech recognition.
Thanks in advance.