I recently tried writing a basic speech recognition using C# (WinFormsApp) in VS 2010 on a Windows 7 Dell computer. I was able to make it work using the basic examples from microsoft (http://msdn.microsoft.com/en-us/magazine/cc163663.aspx#S5) and from forums like this one. However, I needed to change computers and now I am trying to replicate this on a Lenovo computer with the same specs. It does not work, in fact, the speech recognition keeps interfering with the program running and when I changed to the SpeechRecognitionEngine
it still doesn't run.
I am able to compile with no error, but I do not see a result, that is, the MessageBox showing the e.Result.Text
.
My code is below:
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.Recognition;
using System.Threading;
namespace SpeechRecogTest
{
public partial class Form1 : Form
{
SpeechRecognitionEngine sr = new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Create grammar
Choices words = new Choices();
words.Add("Hi");
words.Add("No");
words.Add("Yes");
Grammar wordsList = new Grammar(new GrammarBuilder(words));
wordsList.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecognized);
sr.LoadGrammar(wordsList);
}
void rec_SpeechRecognized(object sender, RecognitionEventArgs e)
{
MessageBox.Show(e.Result.Text);
}
}
}
I would really appreciate all your help. I am pretty sure I have installed all the SDKs, including SAPI 5.1, Windows SDK v7.0 and v7.1, I have also included the speech libraries for both COM and NET, and I built a synthesizer that works.