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; using System.Speech.Synthesis; using System.Speech.Recognition; using System.Speech.Recognition.SrgsGrammar; using System.Threading; namespace SpeechToText { public partial class Form1 : Form { SpeechSynthesizer sSynth = new SpeechSynthesizer(); PromptBuilder pBuilder = new PromptBuilder(); SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { pBuilder.ClearContent(); pBuilder.AppendText(textBox1.Text); sSynth.Speak(pBuilder); } private void button2_Click(object sender, EventArgs e) { button2.Enabled = false; button3.Enabled= true; Choices sList = new Choices(); sList.Add(new string[] { "hello","hi","how","are","you","srinivas","test","i"}); Grammar gr = new Grammar(new GrammarBuilder(sList)); try { sRecognize.RequestRecognizerUpdate(); sRecognize.LoadGrammar(gr); sRecognize.SpeechRecognized += sRecognize_SpeechRecognized; sRecognize.SetInputToDefaultAudioDevice(); sRecognize.RecognizeAsync(RecognizeMode.Multiple); } catch { return; } /* sRecognize.SetInputToDefaultAudioDevice(); sRecognize.LoadGrammar(new DictationGrammar()); sRecognize.SpeechRecognized += new EventHandler(sRecognize_SpeechRecognized); sRecognize.RecognizeAsync(RecognizeMode.Multiple);*/ } void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { /* foreach (RecognizedWordUnit word in e.Result.Words) { listBox1.Items.Add(word.Text); }*/ if (e.Result.Text == "exit") { Application.Exit(); } else { textBox1.Text = textBox1.Text + " " + e.Result.ToString(); } } private void Form1_Load(object sender, EventArgs e) { // sRecognize.SpeechRecognized += new EventHandler(sRecognize_SpeechRecognized); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)