终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

92 rivejä
2.6 KiB

  1. using BPA.Helper;
  2. using System;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace BPASmartClient.CustomResource
  11. {
  12. public class VoiceAPI
  13. {
  14. public VoiceAPI()
  15. {
  16. }
  17. static VoiceAPI()
  18. {
  19. BPA.Helper.ThreadManage.GetInstance().StartLong(new Action(() =>
  20. {
  21. while (msg.Count > 0)
  22. {
  23. if (msg.TryDequeue(out string str))
  24. {
  25. WaitMeaLSpeak(str);
  26. }
  27. }
  28. Thread.Sleep(1000);
  29. }), "语音播报", true);
  30. }
  31. [DllImport("winmm.dll")]
  32. public static extern bool PlaySound(string pszSound, int hmod, int fdwSound);
  33. private static ConcurrentQueue<string> msg { get; set; } = new ConcurrentQueue<string>();
  34. public static void Speak(string s)
  35. {
  36. if (int.TryParse(s.Substring(0, s.Length - 1), out int num))
  37. msg.Enqueue(num.ToString("0000"));
  38. }
  39. // 系统播放wav格式的文件
  40. private static void m_SystemPlayWav(string strPlayFile)
  41. {
  42. try
  43. {
  44. if (strPlayFile.Trim() == "")
  45. { return; }//为空不放
  46. string strPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
  47. strPath = strPath + strPlayFile;
  48. int SND_FILENAME = 0x00020000;
  49. int SND_ASYNC = 0x0001;
  50. PlaySound(strPath, 0, SND_ASYNC | SND_FILENAME);//播放音乐
  51. }
  52. catch (Exception ex)
  53. {
  54. MessageLog.GetInstance.ShowEx(ex.Message);
  55. }
  56. }
  57. private static void WaitMeaLSpeak(string meal, int count = 1, int IntervalTime = 1000)
  58. {
  59. m_SystemPlayWav(@"Vioce\电子提示音.wav");
  60. Thread.Sleep(1000);
  61. for (int m = 0; m < count; m++)
  62. {
  63. m_SystemPlayWav(@"Vioce\请.wav");
  64. Thread.Sleep(500);
  65. for (int i = 0; i < meal.Length; i++)
  66. {
  67. string name = meal.Substring(i, 1);
  68. m_SystemPlayWav($"Vioce\\{name}.wav");
  69. Thread.Sleep(500);
  70. }
  71. m_SystemPlayWav(@"Vioce\号用户取餐.wav");
  72. Thread.Sleep(1500 + IntervalTime);
  73. }
  74. }
  75. }
  76. }