0

Hi i have situation here i don't know how to solve this. This code is fine with 0 Errors but whenever i do F5 it shows me a blank form with no voice and no recognition please help . Please i really need help can someone help me please.
Now this line is only for "it look like your post is mostly code; please add some more details";

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Speech.Synthesis; using System.Speech.Recognition; using System.Threading; namespace a.i { public partial class Form1 : Form { SpeechSynthesizer s = new SpeechSynthesizer(); Choices list = new Choices(); public Form1() { SpeechRecognitionEngine rec = new SpeechRecognitionEngine(); list.Add(new String[] { "hello", "how are you" }); Grammar gr = new Grammar(new GrammarBuilder(list)); try { rec.RequestRecognizerUpdate(); rec.LoadGrammar(gr); rec.SpeechRecognized += rec_SpeachRecognized; rec.SetInputToDefaultAudioDevice(); rec.RecognizeAsync(RecognizeMode.Multiple); } catch { return; } s.SelectVoiceByHints(VoiceGender.Neutral); s.Speak("Hello, my name is Gabriel ChatterBot"); InitializeComponent(); } public void say(string h) { s.Speak(h); } private void rec_SpeachRecognized(object sender, SpeechRecognizedEventArgs e) { String r = e.Result.Text; //what you say if (r == "hello") { // what it says say("hi"); } //what you say if (r == "how are you") { // what it says say("Great, and you!"); } } } } 
4
  • 1
    Most likely there is an exception thrown in the constructor. Due to the return in the catch block InitializeComponents is not called... Commented Jan 13, 2017 at 20:58
  • @ThomasVoß i tryed to put InitializeComponent(); can you edit my code please i really need to get this done. Commented Jan 13, 2017 at 21:22
  • 1
    I don't know what type of problem your code has, but try replaceing catch { return; } with catch Exception ex {MessageBox.Show(ex.ToString();}. This will show you if you have an Exception throw in your try block. For further help it would be helpful if you poste that message. Commented Jan 13, 2017 at 23:35
  • @ThomasVoß it worked but now it's saying System.InvalidOperationException “The language for the grammar does not match the language of the speech recognizer” what should i do? Commented Jan 14, 2017 at 20:08

1 Answer 1

1

From the exception you posted, I think that you have not initionalized the Grammar and SpeechRecognitionEngine correctly. It seems that you need to specify a language / culture for it. From the documentation at: https://msdn.microsoft.com/en-us/library/hh378426(v=office.14).aspx

// Create a new SpeechRecognitionEngine instance. SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.