VoicePlay.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace MeterPlugInLibrary
  10. {
  11. public class VoicePlay
  12. {
  13. private string m_szRunPath = System.Environment.CurrentDirectory;
  14. private VoiceMCI vmciClass = new VoiceMCI();
  15. /// <summary>
  16. /// 语音播放
  17. /// </summary>
  18. /// <param name="strvoiceName"></param>
  19. /// <param name="strPntName">车牌号</param>
  20. public void GetVoicePlay(string strvoiceName, string strCarNo)
  21. {
  22. try
  23. {
  24. WriteLog("车牌号:" + strCarNo + " 当前准备播放:" + strvoiceName);
  25. //判断是否存在语音,存在则语音播报
  26. bool isHaveVoice = false;
  27. foreach (string str in PbCache.voiceInfo)
  28. {
  29. if (strvoiceName == str)
  30. {
  31. isHaveVoice = true;
  32. break;
  33. }
  34. }
  35. if (!isHaveVoice) return; //不存在语音则不进行后面播放操作
  36. if (!PbCache.voiceOver || PbCache.monitor.isEnableSound == "0") return;//语音未播完
  37. PbCache.voiceOver = false;
  38. WriteLog("车牌号:" + strCarNo + " 语音播放:" + strvoiceName);
  39. strvoiceName = strvoiceName + ".wav";
  40. string path = m_szRunPath + "\\Sound\\" + strvoiceName;
  41. int intVmci = vmciClass.VoicePlay(path);
  42. WriteLog("车牌号:" + strCarNo + " 语音播放结果( -1语音播放失败 0无音频设备 1语音播放成功 2语音播放结束):" + intVmci);
  43. }
  44. catch (Exception exp)
  45. {
  46. WriteLog("语音播放异常!" + strvoiceName + " " + exp.Message);
  47. }
  48. }
  49. private void WriteLog(string str)
  50. {
  51. // 20220925 By BourneCao 暂时屏蔽语音播放日志
  52. return ;
  53. string m_szRunPath;
  54. m_szRunPath = System.Environment.CurrentDirectory;
  55. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  56. {
  57. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  58. }
  59. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  60. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  61. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  62. {
  63. Directory.CreateDirectory(strPathFile);
  64. }
  65. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\语音播放_" + strDate + ".log", true);
  66. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  67. tw.WriteLine(str);
  68. tw.WriteLine("\r\n");
  69. tw.Close();
  70. }
  71. }
  72. }