First, you add a library for speech recognition.
using System.Speech.Recognition
If you cannot load the library, you can add it using the add link. Go
Project> Add Link> Overview
Typically, System.Speech.dll is located in the folder C: \ Program Files \ Reference Assemblies \ Microsoft \ Framework \ v3.0
Here is an example code that recognizes Yes, No, B, Output, below:
namespace SpeechRecognition { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SpeechRecognizer sr = new SpeechRecognizer(); Choices ch = new Choices(); ch.Add(new string[] { "yes", "no","in","out" }); GrammarBuilder gb = new GrammarBuilder(); gb.Append(ch); Grammar gr = new Grammar(gb); sr.LoadGrammar(gr); sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognition); } private void sr_SpeechRecognition(object sender, SpeechRecognizedEventArgs e) { MessageBox.Show(e.Result.Text); } } }
Sevki Bekir
source share