日期:2014-05-17 浏览次数:21114 次
using System.Windows.Forms; using System.Speech.Recognition;//包 using System.Speech; namespace VoiceControl { public partial class Form1 : Form { private SpeechRecognitionEngine SRE = new SpeechRecognitionEngine(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SRE.SetInputToDefaultAudioDevice(); GrammarBuilder GB = new GrammarBuilder(); GB.Append("选择"); GB.Append(new Choices(new string[] { "红色", "绿色" })); Grammar G = new Grammar(GB); G.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(G_SpeechRecognized); SRE.LoadGrammar(G); SRE.RecognizeAsync(RecognizeMode.Multiple); } void G_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result.Text.Equals("选择红色")) { BackColor = Color.Red; } else if (e.Result.Text.Equals("选择绿色")) { BackColor = Color.Green; } } } }