| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CarLocalMeter
- {
- public class VoicePlay
- {
- private string m_szRunPath = Environment.CurrentDirectory;
- private VoiceMCI vmciClass = new VoiceMCI();
- /// <summary>
- /// 语音播放
- /// </summary>
- /// <param name="strvoiceName"></param>
- /// <param name="strPntName">车牌号</param>
- public void GetVoicePlay(VoiceEnum strvoiceName, string strCarNo)
- {
- try
- {
- WriteLog("车牌号:" + strCarNo + " 当前准备播放:" + strvoiceName);
- //判断是否存在语音,存在则语音播报
- bool isHaveVoice = false;
- foreach (string str in CacleCls.voiceInfo)
- {
- if (strvoiceName.ToString() == str)
- {
- isHaveVoice = true;
- break;
- }
- }
- if (!isHaveVoice) return; //不存在语音则不进行后面播放操作
- if (!CacleCls.voiceOver) return;//语音未播完
- CacleCls.voiceOver = false;
- WriteLog("车牌号:" + strCarNo + " 语音播放:" + strvoiceName);
- string path = $"{m_szRunPath}\\Sound\\{strvoiceName}.wav";
- int intVmci = vmciClass.VoicePlay(path);
- WriteLog("车牌号:" + strCarNo + " 语音播放结果( -1语音播放失败 0无音频设备 1语音播放成功 2语音播放结束):" + intVmci);
- }
- catch (Exception exp)
- {
- WriteLog("语音播放异常!" + strvoiceName + " " + exp.Message);
- }
- }
- private void WriteLog(string str)
- {
- // 20220925 By BourneCao 暂时屏蔽语音播放日志
- return;
- string m_szRunPath;
- m_szRunPath = System.Environment.CurrentDirectory;
- if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
- {
- System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
- }
- string strDate = System.DateTime.Now.ToString("yyyyMMdd");
- string strPathFile = m_szRunPath + "\\log\\" + strDate;
- if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
- {
- Directory.CreateDirectory(strPathFile);
- }
- System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\语音播放_" + strDate + ".log", true);
- tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- tw.WriteLine(str);
- tw.WriteLine("\r\n");
- tw.Close();
- }
- }
- public enum VoiceEnum
- {
- 车辆未停到位,
- 开始计量,
- 车辆超重,
- 计量完成,
- 结净重量过小,
- 仪表未归零,
- 两次计量重量接近,
- 车号未识别,
- 程序处理异常,
- 计量完成多委托
- }
- }
|