kalpesh nariya

kalpesh nariya

  • NA
  • 26
  • 7.9k

How to convert .wav file into Text format using asp.net Mvc4

Jan 30 2015 6:27 AM
Hi,

i have a wave file and want to convert that into Text format using asp.net

i tried the below code but it not understood when audio file is end.

Index.chtml

@model MvcApplication1.Models.Home @{ ViewBag.Title = "Home Page"; }   @using (Html.BeginForm()) { <input type="button" onclick="callfun()" value="Get" /> @Html.HiddenFor(m => m.txtval) @Html.LabelFor(m => m.txtval) } <script> function callfun() { $.ajax({ url: 'Home/Find', dataType: "json", type: "POST", contentType: 'application/json; charset=utf-8', //pageNo: 2, pageSize: 20 would not be posted to the action, //it would be 3 and 5 as we specified it at ajax url //and user would be null data: {}, async: true, processData: false, cache: false, success: function (data) { alert(data); }, error: function (xhr) { alert('error'); } }) } </script>

HomeController


public ActionResult Index() { ViewBag.Message = "WavToTxt"; return View(); }

[HttpPost] public async Task Find() { SpeechRecognitionEngine sre = new SpeechRecognitionEngine(); Grammar gr = new DictationGrammar(); sre.LoadGrammar(gr); //sre.LoadGrammarAsync(gr); sre.SetInputToWaveFile("D:\\arth_mb.wav"); //sre.SetInputToWaveStream("D:\\arth_mb.wav"); sre.BabbleTimeout = new TimeSpan(Int32.MaxValue); sre.InitialSilenceTimeout = new TimeSpan(Int32.MaxValue); sre.EndSilenceTimeout = new TimeSpan(100000000); sre.EndSilenceTimeoutAmbiguous = new TimeSpan(100000000); sre.SpeechRecognized += new EventHandler(sre_SpeechRecognized); sre.RecognizeCompleted += new EventHandler(sre_RecognizeCompleted); Home hm = new Home();   while (!completed) { try { var cnt = sre.Recognize().ToString().Length; var recText = sre.Recognize(); if (recText == null) { break; } hm.txtval += recText.Text; } catch (Exception ex) { //handle exception //... //break; Response.End(); completed = true; } } return View(hm.txtval); //return Json(hm.txtval, JsonRequestBehavior.AllowGet); }   static void sre_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e) { if (e.Error != null) { Console.WriteLine(" Error encountered, {0}: {1}", e.Error.GetType().Name, e.Error.Message); } if (e.Cancelled) { Console.WriteLine(" Operation cancelled."); } if (e.InputStreamEnded) { Console.WriteLine(" End of stream encountered."); }   completed = true; } static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { Home hm = new Home();   if (e.Result != null && e.Result.Text != null) { Console.WriteLine(" Recognized text = {0}", e.Result.Text); } else { Console.WriteLine(" Recognized text not available."); } }