using FluentScheduler; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Speech.Synthesis; using System.Text; namespace JwKdsV.Core.Job { public class VoPlayJob : IJob { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); public void Execute() { try { if (Global.VoPlayQueue.Count > 0) { logger.Debug("定时任务:出品同步语音播报..."); var line = Global.VoPlayQueue.Dequeue(); SpeechSynthesizer speaker = new SpeechSynthesizer(); speaker.SetOutputToDefaultAudioDevice(); speaker.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult, 2, System.Globalization.CultureInfo.CurrentCulture); speaker.Rate = -2; speaker.Volume = 100; string strBuff = " "; string stringWithoutFirstChar = ""; string newString = line.ToString(); //newString = "T0016"; //newString = "D0006"; if (newString[0] == 'T') { stringWithoutFirstChar = newString.Substring(1); if (int.TryParse(stringWithoutFirstChar, out int number)) { strBuff = "请" + number + "号取餐";//"请" + order.OrderNo + "号取餐" speaker.SpeakAsync(strBuff); } else { logger.Debug("数据有异常..."); } } else if (newString[0] == 'D') { stringWithoutFirstChar = newString.Substring(1); if (int.TryParse(stringWithoutFirstChar, out int number)) { strBuff = "请" + number + "号打包取餐";//"请" + order.OrderNo + "号取餐" speaker.SpeakAsync(strBuff); } else { logger.Debug("数据有异常..."); } } else { stringWithoutFirstChar = newString; if (int.TryParse(stringWithoutFirstChar, out int number)) { strBuff = "请" + number + "号取餐";//"请" + order.OrderNo + "号取餐" speaker.SpeakAsync(strBuff); } else { logger.Debug("数据有异常..."); } } } } catch (Exception ex) { logger.Error(ex, "定时任务:出品同步播报异常"); } } } }