Hello.
I have problem with Emgu cv and Microsoft Speech.
Speech recognition works fine until I turn on face detection (button1_Click).
Where is problem? What I'm doing wrong?
I'm thinking the problem may be in:
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
and
Application.Idle += new EventHandler(FrameGrabber);
but I don't know how solve this.
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using Emgu.CV;
- using Emgu.CV.Structure;
- using Emgu.CV.CvEnum;
- using System.IO;
- using System.Diagnostics;
- using Microsoft.Speech.Recognition;
- using Microsoft.Speech.Synthesis;
-
- namespace MultiFaceRec
- {
- public partial class FrmPrincipal : Form
- {
-
- Image<Bgr, Byte> currentFrame;
- Capture grabber;
- HaarCascade face;
- HaarCascade eye;
- MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);
- Image<Gray, byte> result, TrainedFace = null;
- Image<Gray, byte> gray = null;
- List<Image<Gray, byte>> trainingImages = new List<Image<Gray, byte>>();
- List<string> labels= new List<string>();
- List<string> NamePersons = new List<string>();
- int ContTrain, NumLabels, t;
- string name, names = null;
-
-
- SpeechSynthesizer synth = new SpeechSynthesizer();
-
- public FrmPrincipal()
- {
- InitializeComponent();
-
- face = new HaarCascade("haarcascade_frontalface_default.xml");
-
- synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (pl-PL, Paulina)");
- synth.SetOutputToDefaultAudioDevice();
-
- System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("pl-PL");
- SpeechRecognitionEngine sre = new SpeechRecognitionEngine(ci);
- sre.SetInputToDefaultAudioDevice();
- sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
- Choices numbers = new Choices();
- numbers.Add(new string[] { "Pierwszy test aplikacji.", "dwa", "szczyt", "jeden"});
-
- GrammarBuilder gb = new GrammarBuilder();
- gb.Append(numbers);
- Grammar g = new Grammar(gb);
- sre.LoadGrammar(g);
-
- sre.RecognizeAsync(RecognizeMode.Multiple);
-
- try
- {
-
- string Labelsinfo = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
- string[] Labels = Labelsinfo.Split('%');
- NumLabels = Convert.ToInt16(Labels[0]);
- ContTrain = NumLabels;
- string LoadFaces;
-
- for (int tf = 1; tf < NumLabels+1; tf++)
- {
- LoadFaces = "face" + tf + ".bmp";
- trainingImages.Add(new Image<Gray, byte>(Application.StartupPath + "/TrainedFaces/" + LoadFaces));
- labels.Add(Labels[tf]);
- }
-
- }
- catch(Exception e)
- {
-
- MessageBox.Show("Nothing in binary database, please add at least a face(Simply train the prototype with the Add Face Button).", "Triained faces load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
-
- }
-
- private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
- {
- if (e.Result.Confidence > 0.82)
-
- {
- label6.Text = e.Result.Text;
- synth.Speak("Powiedziales: ");
- synth.SpeakAsync(label6.Text);
-
- }
-
- return;
- }
-
-
- private void button1_Click(object sender, EventArgs e)
- {
-
- grabber = new Capture();
- grabber.QueryFrame();
-
- Application.Idle += new EventHandler(FrameGrabber);
- button1.Enabled = false;
- }