/// <summary> /// 初始化ActiveMQ /// </summary> /// <param name="flag">0表示主链接,1 表示航显链接,-1表示关闭ActiveMQ</param> public void Initialize(int flag) { try { if (connection != null) { connection.Close(); } string url = ActiveMQUrl, userName = UserName, pwd = Pwd, queueName = QueueName; switch (flag) { case 0: url = ActiveMQUrl; userName = UserName; pwd = Pwd; queueName = QueueName; break; case 1: url = ActiveMQUrlBak; userName = UserNameBak; pwd = PwdBak; queueName = QueueName; break; default: return; } //创建连接工厂 // IConnectionFactory factory = new ConnectionFactory( new Uri(string.Format("activemq:failover:(tcp://{0})", url))); IConnectionFactory factory = new ConnectionFactory(new Uri(string.Format("failover:(tcp://{0})?randomize=false", url))); //通过工厂创建连接 connection = factory.CreateConnection(userName, pwd); //connection = factory.CreateConnection(); //连接服务器端的标识 connection.ClientId = GetLocalIP() + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // "firstQueueListener"; //启动连接 connection.Start(); connection.ConnectionInterruptedListener += Connection_ConnectionInterruptedListener; connection.ConnectionResumedListener += Connection_ConnectionResumedListener; connection.ExceptionListener += Connection_ExceptionListener; //通过连接创建对话 ISession session = connection.CreateSession(); // IMessageConsumer consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(queueName), Selector); IMessageConsumer consumer = session.CreateDurableConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(queueName), connection.ClientId, null, false); //注册监听事件 consumer.Listener += new MessageListener(consumer_Listener); ReceivedData += ActiveMQListener_ReceivedData; // consumer.ReceiveNoWait(); VoiceBroadcastUtil.jTTS_Init(null, null); } catch (Exception e) { } }
public void HandPlayText(HandPlayTextDto input) { #region 生成文件名称 var todayPath = DateTime.Today.ToString("yyyy-MM-dd"); string root_path = Path.Combine(appFolders.AudioFolder, "Temp", todayPath); if (!Directory.Exists(root_path)) { Directory.CreateDirectory(root_path); } string wavName = "HandTxt_" + Guid.NewGuid().ToString().Replace("-", "") + ".wav"; string outputFile = Path.Combine(root_path, wavName); #endregion #region 生成播放文件,根据次数循环,拼接在一个文件 var playtext = ""; if (input.PlayTimes < 1) { return; } for (int i = 0; i < input.PlayTimes; i++) { playtext = playtext + ",,,,," + input.PlayText; } VoiceBroadcastUtil.PlayTextToFile(playtext, outputFile); #endregion #region 组装需打开的电源控制器的端口 var entitys = topPwrRepository.GetAll().Where(x => input.TopPortIds.Contains(x.Id)).ToList(); string port = "00000000"; entitys.ForEach(x => { var index = int.Parse(x.Code); port = port.Substring(0, index - 1) + "1" + port.Substring(index); }); #endregion #region 查询所有声卡 ,暂未用到 var des = deviceRepository.GetAllList().Select(x => x.Name).ToList(); #endregion _play.PlayText(outputFile, port, des); // VoiceBroadcastUtil.PlayText(input.PlayText); }