VoicePlay.cs 2.9 KB

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