views:

1425

answers:

5

There is a post in here about that ...but it doesn't work for me. I have added a system.speech.dll that I found in the internet but i cannot use System.speech , because it doesn't appear.

Error 1 The type or namespace name 'SpeechRecognizer' could not be found (are you missing a using directive or an assembly reference?)

Error 2 The type or namespace name 'SpeechRecognizedEventArgs' could not be found (are you missing a using directive or an assembly reference?)

I have used this code. I am using Windows Vista 64

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 SpeechLib;
using System.Threading;


namespace WindowsFormsApplication13
{
    public partial class Form1 : Form
    {

        SpeechRecognizer rec = new SpeechRecognizer();

        public Form1()
        {
            InitializeComponent();
            rec.SpeechRecognized += rec_SpeechRecognized;
        }

        void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            lblLetter.Text = e.Result.Text;
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            var c = new Choices();

            // Doens't work must use English words to add to Choices and
            // populate grammar.
            //
            //for (var i = 0; i <= 100; i++)
            //  c.Add(i.ToString());

            c.Add("one");
            c.Add("two");
            c.Add("three");
            c.Add("four");
            c.Add("Five");
            c.Add("six");
            c.Add("seven");
            c.Add("eight");
            c.Add("nine");
            c.Add("ten");

            // etc...

            var gb = new GrammarBuilder(c);
            var g = new Grammar(gb);
            rec.LoadGrammar(g);
            rec.Enabled = true;
        }
    }
}
+3  A: 

1) You need to add a reference to System.Speech in your project

2) You shouldn't have had to find 'System.Speech.dll' on the Internet, it should be in .Net 3 (or 3.5, but get 3.5 anyway unless you've a compelling reason not to)

James

Edit:

You might want to look here:

http://dotnet.org.za/beta/archive/2008/01/06/system-speech-recognition.aspx

James Ogden
Thanks but now I have another problem when I debug in form load the programs doesn't do anything at all. and if i put a second code in a button the program says I dont have a recognizer instaled. Can you help me in this one?
+2  A: 

I agree with James Ogden. Also, you should add a "using" statement:

using System.Speech.Recognition

Or, fully qualify your class names.

BobbyShaftoe
A: 

Thanks but now I have another problem when I debug in form load the programs doesn't do anything at all. and if i put a second code in a button the program says I dont have a recognizer instaled. Can you help me in this one?

A: 

While not directly applicable to the above question - it is worth noting that the Speech SDK will not nessecarily be availible on each clients machines. While Vista includes a speech recognizer, XP does not. A possible way to correct this is to get the XP users to install the Speech SDK, which includes one. The other is to add Office 2003 (not 2007) as a dependency.

+1  A: 

Check that you have a language engine matching the language you have configured in Vista. See http://support.microsoft.com/kb/934377

Conor OG