/// <summary> /// 纯文本模式 /// </summary> public void JustTextModel() { try { //可以再次执行录音、语音转换 this.isInTransfer = false; //指定文件名称进行转译 string message = AudioTransfer.AudioToText(this.wave.SavedFile); //异步委托 this.Dispatcher.BeginInvoke(new Action(() => { string beforeText = this.txtInput.Text; this.txtInput.Text = beforeText + " " + message; })); //this.Dispatcher.BeginInvoke(new Action(() => // { // string beforeText = this.txtInput.Text; // this.txtInput.Text = beforeText + " " + "转译成功"; // })); ////可以再次执行录音、语音转换 //this.isInTransfer = false; } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }
public void SettingAudioTransferTxt(int conferenceID, ConferenceAudioItemTransferEntity conferenceAudioItemTransferEntity) { //上锁,达到线程互斥作用 lock (objTransfer) { try { //当前会议为null,则不执行下列操作 if (conferenceID == 0) { return; } if (string.IsNullOrEmpty(conferenceAudioItemTransferEntity.AudioMessage)) { //音频文件字节数组 byte[] array = null; //获取webservice路径 string strLocal = this.Server.MapPath("."); conferenceAudioItemTransferEntity.AudioFileName = Path.GetFileName(conferenceAudioItemTransferEntity.AudioUrl); string fileName = strLocal + "\\" + Constant.AudioLocalRootName + "\\" + conferenceAudioItemTransferEntity.AudioFileName; if (File.Exists(fileName)) { //通过文件流将音频文件转为字节数组 using (System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.Delete)) { array = new byte[fileStream.Length]; //将文件流读出给指定字节数组 fileStream.Read(array, 0, array.Length); } AudioFileType audioFileType = (AudioFileType)Enum.Parse(typeof(AudioFileType), Path.GetExtension(fileName).Replace(".", string.Empty)); //语音转文字(通用方法) string message = AudioTransfer.AudioToText(array, audioFileType); //结束语音识别 if (string.IsNullOrEmpty(message)) { message = "无法识别"; } //操作方式改为更新 conferenceAudioItemTransferEntity.Operation = ConferenceAudioOperationType.UpdateType; //语音文本 conferenceAudioItemTransferEntity.AudioMessage = message; //更新一个节点 this.UpdateOne(conferenceID, conferenceAudioItemTransferEntity); } } } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } } }