using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Speech; using System.Speech.Recognition; namespace spechToText { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); // open.Filter = "AUDIO file|* .wav |file audio|* .wma"; if(open.ShowDialog() == DialogResult.OK) { SpeechRecognitionEngine sre = new SpeechRecognitionEngine(); Grammar gr = new DictationGrammar(); sre.LoadGrammar(gr); sre.SetInputToWaveFile(open.FileName); sre.BabbleTimeout = new TimeSpan(Int32.MaxValue); sre.InitialSilenceTimeout = new TimeSpan(Int32.MaxValue); sre.EndSilenceTimeout = new TimeSpan(100000000); sre.EndSilenceTimeoutAmbiguous = new TimeSpan(100000000); StringBuilder sb = new StringBuilder(); while (true) { try { var recText = sre.Recognize(); if (recText == null) { break; } sb.Append(recText.Text); } catch (Exception ex) { //handle exception //... break; } } richTextBox1.AppendText( sb.ToString()); } } private void Form1_Load(object sender, EventArgs e) { } private void richTextBox1_TextChanged(object sender, EventArgs e) { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)