Getting error like are you missing an assembly reference in my program
i am using this code in .net framework 3.5 , for creating a grammar using visual studio 2010 professional in win 7 but i am getting errors like The type or namespace name 'Speech' does not exist in system (are you missing a using directive or an assembly reference.
The type or namespace name 'SpeechRecognitionType' could not be found (are you missing a using directive or an as开发者_C百科sembly reference,
similarly others like type linq does not exist are you an missing an assembly refernce.
`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);
}
}
}`
As it asks "are you missing a using directive or an assembly reference"? You're not missing the using directive, therefore it's likely you're missing the assembly. Right-click on "References" => "Add Reference" => NET tab => System.Speech dll.
精彩评论