//private SpeechRecognizer speech = new SpeechRecognizer(); public MainWindow() { InitializeComponent(); //1 /* * SpeechSynthesizer synthesizer = new SpeechSynthesizer(); * synthesizer.Speak("Hello,world.my name is ok baba"); */ //2 /* * PromptBuilder prompt = new PromptBuilder(); * prompt.AppendText("Hello,world.my name is ok baba"); * SpeechSynthesizer synthesizer = new SpeechSynthesizer(); * synthesizer.Speak(prompt); */ /* * speech.SpeechDetected += Speech_SpeechDetected; * speech.SpeechHypothesized += Speech_SpeechHypothesized; * speech.SpeechRecognized += Speech_SpeechRecognized; * speech.SpeechRecognitionRejected += Speech_SpeechRecognitionRejected; * button1.Focus(); //按钮获取输入焦点 * */ 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); }
public void StartRecognizing() { SRE.RecognizeAsync(RecognizeMode.Multiple); }