|
-
- using BPA.Helper;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.CustomResource
- {
- public class VoiceAPI
- {
- public VoiceAPI()
- {
-
- }
-
- static VoiceAPI()
- {
- BPA.Helper.ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- while (msg.Count > 0)
- {
- if (msg.TryDequeue(out string str))
- {
- WaitMeaLSpeak(str);
- }
- }
-
- Thread.Sleep(1000);
-
- }), "语音播报", true);
- }
-
- [DllImport("winmm.dll")]
- public static extern bool PlaySound(string pszSound, int hmod, int fdwSound);
-
- private static ConcurrentQueue<string> msg { get; set; } = new ConcurrentQueue<string>();
-
-
- public static void Speak(string s)
- {
- if (int.TryParse(s.Substring(0, s.Length - 1), out int num))
- msg.Enqueue(num.ToString("0000"));
- }
-
-
- // 系统播放wav格式的文件
- private static void m_SystemPlayWav(string strPlayFile)
- {
- try
- {
- if (strPlayFile.Trim() == "")
- { return; }//为空不放
-
- string strPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
- strPath = strPath + strPlayFile;
-
- int SND_FILENAME = 0x00020000;
- int SND_ASYNC = 0x0001;
- PlaySound(strPath, 0, SND_ASYNC | SND_FILENAME);//播放音乐
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.Message);
- }
- }
-
- private static void WaitMeaLSpeak(string meal, int count = 1, int IntervalTime = 1000)
- {
- m_SystemPlayWav(@"Vioce\电子提示音.wav");
- Thread.Sleep(1000);
- for (int m = 0; m < count; m++)
- {
- m_SystemPlayWav(@"Vioce\请.wav");
- Thread.Sleep(500);
- for (int i = 0; i < meal.Length; i++)
- {
- string name = meal.Substring(i, 1);
- m_SystemPlayWav($"Vioce\\{name}.wav");
- Thread.Sleep(500);
- }
- m_SystemPlayWav(@"Vioce\号用户取餐.wav");
- Thread.Sleep(1500 + IntervalTime);
- }
- }
- }
- }
|