本文介绍了如何使用asp.net Mvc4将.wav文件转换为文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如何使用asp.net mvc4将wav文件转换为文本格式 i有一个wave文件,并希望使用asp.net将其转换为Text格式 i尝试下面的代码,但是当音频文件结束时它不明白。 索引 How to convert wav file into Text format using asp.net mvc4Hi, 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@model MvcApplication1.Models.Home@{ ViewBag.Title = "Home Page";}We suggest the following:@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: "GET", 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 HomeControllerpublic ActionResult Index(){ ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View("Index");} [HttpGet]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."); }} 推荐答案 HomeController HomeControllerpublic ActionResult Index(){ ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View("Index");} [HttpGet]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."); }} 这篇关于如何使用asp.net Mvc4将.wav文件转换为文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 10:07