public partial class EnVoiceUC : UserControl { public EnVoiceUC() { InitializeComponent(); } string[] dialogs = Program.dlgArr; private void Recorder_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { Form1 f1 = new Form1(); string recText = e.Result.Text; for (int i = 0; i < dialogs.Length; i++) { if(dialogs[i]==recText) { try { ((Form)this.TopLevelControl).Hide(); f1.ShowDialog(); ((Form)this.TopLevelControl).Close(); } catch {;} } } } private void DoRecord_Click(object sender, EventArgs e) { System.Media.SystemSounds.Beep.Play(); VoiceRecorder(true); } public void VoiceRecorder(bool enable) { Choices voices = new Choices(); SpeechRecognitionEngine recorder = new SpeechRecognitionEngine(); voices.Add(dialogs); Grammar gramer = new Grammar(new GrammarBuilder(voices)); label2.Visible = enable; if (enable) { try { recorder.RequestRecognizerUpdate(); recorder.LoadGrammar(gramer); recorder.SpeechRecognized += Recorder_SpeechRecognized; recorder.SetInputToDefaultAudioDevice(); recorder.RecognizeAsync(RecognizeMode.Multiple); } catch { return; } } else { try { recorder.UnloadGrammar(gramer); } catch { return; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)