Commit a29186b1 authored by 周亚武's avatar 周亚武

主界面调试及语音

parent 769dee92
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
</properties> </properties>
</profile> </profile>
<profile> <profile>
<id>reg</id> <id>dy</id>
<properties> <properties>
<profiles.active>dy</profiles.active> <profiles.active>dy</profiles.active>
<profiles.filepath>/tmp</profiles.filepath> <profiles.filepath>/tmp</profiles.filepath>
...@@ -135,6 +135,12 @@ ...@@ -135,6 +135,12 @@
<version>5.13.0</version> <version>5.13.0</version>
</dependency> </dependency>
<dependency>
<groupId>javazoom</groupId>
<artifactId>jlayer</artifactId>
<version>1.0.1</version>
</dependency>
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 --> <!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -42,7 +42,7 @@ public class EncryptUtil { ...@@ -42,7 +42,7 @@ public class EncryptUtil {
* @param text * @param text
* @return * @return
*/ */
private static String base64ToString(String text) { public static String base64ToString(String text) {
Base64 base64 = new Base64(); Base64 base64 = new Base64();
try { try {
return new String(base64.decode(text.getBytes("utf-8")), "UTF-8").trim().replace("\n", ""); return new String(base64.decode(text.getBytes("utf-8")), "UTF-8").trim().replace("\n", "");
......
...@@ -2,6 +2,7 @@ package com.mortals.xhx.daemon.applicationservice; ...@@ -2,6 +2,7 @@ package com.mortals.xhx.daemon.applicationservice;
import com.mortals.framework.springcloud.service.IApplicationStartedService; import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.xhx.swing.MyTray; import com.mortals.xhx.swing.MyTray;
import com.mortals.xhx.tts.UI.MainWindow;
import com.mortals.xhx.tts.UI.SettingWindow; import com.mortals.xhx.tts.UI.SettingWindow;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -18,6 +19,9 @@ public class DemoStartedService implements IApplicationStartedService { ...@@ -18,6 +19,9 @@ public class DemoStartedService implements IApplicationStartedService {
@Value("${siteconfig.url:http://192.168.0.98:11091}") @Value("${siteconfig.url:http://192.168.0.98:11091}")
String host; String host;
@Value("${version:4.0.0}")
String version;
@Override @Override
public void start() { public void start() {
log.info("开始服务.."); log.info("开始服务..");
...@@ -36,6 +40,8 @@ public class DemoStartedService implements IApplicationStartedService { ...@@ -36,6 +40,8 @@ public class DemoStartedService implements IApplicationStartedService {
log.info("configPath:{}",configPath); log.info("configPath:{}",configPath);
log.info("host:{}",host); log.info("host:{}",host);
log.info("version:{}",version);
MainWindow.getInstance().initWindow(configPath,host,version);
SettingWindow.getInstance().initWindow(configPath,host); SettingWindow.getInstance().initWindow(configPath,host);
log.info("初始化托盘完成!"); log.info("初始化托盘完成!");
......
package com.mortals.xhx.tts.UI;
import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.google.gson.Gson;
import com.mortals.xhx.common.utils.EncryptUtil;
import com.mortals.xhx.tts.bean.*;
import com.mortals.xhx.tts.utils.*;
import com.rabbitmq.client.*;
import com.sun.media.jfxmedia.events.PlayerStateEvent;
import com.sun.media.jfxmedia.events.PlayerStateListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayerBuilder;
import javazoom.jl.player.Player;
import lombok.extern.slf4j.Slf4j;
import sun.net.www.protocol.file.Handler;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.regex.Pattern;
/**
* @author ZYW
* @date 2024-07-25 9:26
*/
@Slf4j
public class MainWindow {
String configPath = "F:\\\\config.prop";
private static MainWindow instance = null;
static JFrame frame;
Gson gson = new Gson();
String host = "192.168.0.98:11091"; //服务器地址
private String register = "/m/api/register"; //register地址
private String deviceInit = "/m/api/deviceInit"; //初始化信息获取地址
private String deviceUpdate = "/m/api/deviceUpdate"; //手动注册地址
private String checkVersion = "/m/api/checkVersion"; //升级地址
private Integer delayTime = 0; //启动延时
private boolean english = false; //英双语
private boolean zang = false; //藏双语
private String speaker ="tb"; //播音员
String deviceId = null; //设备唯一编号
String httpIndex = "http://"; //http 或 https访问
boolean isOld = false; //是否为利旧设备
static int siteId = 0; // 目前被选中的站点id
static String siteCode = "";
static String siteName = "";
ConnectionFactory factory;
// 联接信息
Connection connection;
// 频道
Channel channel = null;
static String rabbitHost = ""; //rabbitmq服务地址
static String virtualHost = ""; //虚拟机地址
static String downTopicFilter = ""; //消息队列
static String username = ""; //rabbit账号
static String password = ""; //rabbit密码
static int port = 5672; //rabbit端口
int timeout = 86400000; //消息时效 1天86400000
static int enabled = 1; //设备启用状态 (0.停止,1.启用)
boolean isShow = true; //判断本地是否有配置文件 有则设置窗口不可见
String version = "1.0.0";
static TextArea msgArea; //rabbitmq消息显示区域
static TextArea initArea; //初始化消息显示区域
static TextArea voiceArea; //语音播报显示区域
static JLabel noticeArea; //底部提示消息区域
static int msgIndex = 0; //记录第几条rabbit消息 每1000条消息清空一次消息池区域
static int voiceIndex = 0; //记录第几条语音消息 每10条消息清空一次消息池区域
BlockingDeque<FlowNumBean> flowNumBeanList = new LinkedBlockingDeque<FlowNumBean>(); //待播放的语音队列
boolean isCalling = false; //是否在播放语音 作为需要开始播放语音的标志
Player player;
public static void main(String[] args) {
//初始化窗口
getInstance().initWindow(getInstance().configPath, getInstance().host, instance.version);
}
private MainWindow() {
}
public static MainWindow getInstance() {
if (null == instance) {
synchronized (MainWindow.class) {
if (null == instance) {
instance = new MainWindow();
}
}
}
return instance;
}
/**
* 初始化窗口
* @param path
*/
public void initWindow(String path,String hostUrl,String version) {
this.configPath = path;
host = hostUrl;
this.version = version;
//1、创建窗口对象
frame = new JFrame("tts语音播报系统" );
Container c = frame.getContentPane();//获取窗体主容器
c.setLayout(null);
//左侧rabbitmq消息输出区域
JPanel leftPanel = new JPanel();
leftPanel.setBorder(BorderFactory.createTitledBorder("消息队列"));
leftPanel.setBounds(10,0,660,490);
msgArea = new TextArea();
msgArea.setLocation(10,10);
msgArea.setPreferredSize(new Dimension(650,460));
Font font = new Font("宋体", Font.PLAIN, 14);
msgArea.setFont(font);
msgArea.setForeground(Color.black);
msgArea.setVisible(true);
msgArea.setEditable(false);
leftPanel.add(msgArea);
frame.add(leftPanel);
//右侧初始化消息
JPanel rightPanel = new JPanel();
rightPanel.setBounds(680,0,300,240);
rightPanel.setBorder(BorderFactory.createTitledBorder("初始化消息"));
initArea = new TextArea();
initArea.setLocation(690,10);
initArea.setPreferredSize(new Dimension(280,210));
initArea.setFont(font);
initArea.setForeground(Color.black);
initArea.setVisible(true);
initArea.setEditable(false);
rightPanel.add(initArea);
frame.add(rightPanel);
//右侧下方语音播报消息
JPanel voicePanel = new JPanel();
voicePanel.setBounds(680,250,300,240);
voicePanel.setBorder(BorderFactory.createTitledBorder("语音播报"));
voiceArea = new TextArea();
voiceArea.setLocation(690,10);
voiceArea.setPreferredSize(new Dimension(280,210));
voiceArea.setFont(font);
voiceArea.setForeground(Color.black);
voiceArea.setVisible(true);
voiceArea.setEditable(false);
voicePanel.add(voiceArea);
frame.add(voicePanel);
//文字说明区
JPanel bottomPanel = new JPanel(new BorderLayout());
bottomPanel.setBorder(BorderFactory.createTitledBorder("说明"));
bottomPanel.setBounds(10,490,970,80);
noticeArea = new JLabel();
Font font1 = new Font("Serif", Font.PLAIN, 14);
noticeArea.setFont(font1);
noticeArea.setForeground(Color.black);
noticeArea.setVisible(true);
bottomPanel.add(noticeArea,BorderLayout.CENTER);
frame.add(bottomPanel);
//合适的窗口大小
frame.pack();
//禁止改变窗口大小
frame.setResizable(false);
//设置窗口关闭退出软件 默认 JFrame.EXIT_ON_CLOSE会关闭所有窗口 DISPOSE_ON_CLOSE仅关闭当前窗口
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// 获取屏幕尺寸
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
//设置窗口的位置和大小
frame.setBounds((screenWidth-1000)/2,(screenHeight-610)/2,1000,610);
//设置窗口对象不可见
frame.setVisible(isShow);
frame.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
//界面重现时重新读取配置
}
@Override
public void windowDeactivated(WindowEvent e) {
}
});
pushInitMsg("程序开始启动");
readConfig();
if (deviceId == null) {
deviceId = MacAddressReader.getMacAddress();
}
reloadMessage();
initData();
}
/**
* 初始化数据
*/
private void initData() {
pushInitMsg("访问register接口");
DeviceCodeBean cb = new DeviceCodeBean(deviceId, "1");
String result = HttpRequest.post(httpIndex+host+register).body(gson.toJson(cb)).execute().body();
log.info(result);
ResultBean rb = gson.fromJson(result,ResultBean.class);
if(rb.getCode() == 1){
pushInitMsg("register访问成功");
try {
ContentBean contentBean = gson.fromJson(gson.toJson(rb.getData()), ContentBean.class);
String data = EncryptUtil.myReEnscrt(contentBean.getContent(),Constant.ORDERNUM,Constant.DESKEY,Constant.AESKEY);
ResultRabbitBean rmb = gson.fromJson(data, ResultRabbitBean.class);
RabbitMessBean rabbitMessBean = rmb.getRabbmitInfo();
rabbitHost = rabbitMessBean.getHost();
virtualHost = rabbitMessBean.getVirtualHost();
downTopicFilter = rabbitMessBean.getDownTopicFilter();
timeout = Integer.parseInt(rabbitMessBean.getMessageTtl());
username = rabbitMessBean.getUsername();
password = rabbitMessBean.getPassword();
port = rabbitMessBean.getPort();
enabled = rmb.getDeviceInfo().getEnabled();
reloadMessage();
if(enabled == 0){ //设备被禁用了
pushRabbitMsg("设备已被禁用");
}else {
initMQ();
}
}catch (Exception e){
e.printStackTrace();
pushInitMsg("register返回数据解密失败:"+result);
}
}else {
pushInitMsg("register返回异常:"+rb.getMsg());
}
// while (true){
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// FlowNumBean flowNumBean = new FlowNumBean(6, "A00"+(msgIndex%100), "010", "010", System.currentTimeMillis());
// pushRabbitMsg("请"+flowNumBean.getFlownum()+"号到"+flowNumBean.getWindowfromnum()+"号窗口");
// test(flowNumBean);
//
//
// }
}
private void initMQ(){
// 创建连接工厂
factory = new ConnectionFactory();
factory.setHost(rabbitHost);
factory.setUsername(username);
factory.setPassword(password);
factory.setVirtualHost(virtualHost);
factory.setPort(port);
// 关键所在,指定线程池
ExecutorService service = Executors.newFixedThreadPool(10);
factory.setSharedExecutor(service);
// 设置自动恢复
factory.setAutomaticRecoveryEnabled(true);
factory.setNetworkRecoveryInterval(2);// 设置 每10s ,重试一次
factory.setTopologyRecoveryEnabled(false);// 设置不重新声明交换器,队列等信息。
// 创建连接和通道
try {
connection = factory.newConnection();
channel = connection.createChannel();
Map<String, Object> argMap = new HashMap<>();
// 设置消息存活时间
argMap.put("x-message-ttl",timeout); //消息时效性
channel.queueDeclare(downTopicFilter, true, false, false, argMap);
// 设置一条条的应答
channel.basicQos(0, 1, false);
// 创建队列消费者
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
String message = new String(body, "UTF-8");
pushRabbitMsg(message);
handleVoiceMsg(message);
}
};
// 监听队列,autoAck参数为true表示自动确认
channel.basicConsume(downTopicFilter, true, consumer);
pushInitMsg("RabbitMq链接成功");
}catch (Exception e){
pushInitMsg("MQ链接异常:"+e.toString());
e.printStackTrace();
}
}
/**
* 刷新底部提示消息
*/
private void reloadMessage(){
noticeArea.setText("<html>&emsp软件版本 V"+version+"&emsp;&emsp;&emsp;&emsp;服务器:"+host+"&emsp;&emsp;&emsp;&emsp;英双语:"+(english?"开启":"关闭") +
"&emsp;&emsp;&emsp;&emsp;藏双语:"+(zang?"开启":"关闭") +"&emsp;&emsp;&emsp;&emsp;播音员:"+speaker +
"<br>&emsp;消息服务器:"+rabbitHost+ "&emsp;&emsp;&emsp;&emsp;虚拟机:"+virtualHost+ "&emsp;&emsp;&emsp;&emsp;队列:"+downTopicFilter+
"&emsp;&emsp;&emsp;&emsp;本机ip:"+MacAddressReader.getLocalIp()+ "<br>&emsp;设备状态:"+(enabled == 0?"禁用":"启用")+
"&emsp;&emsp;&emsp;&emsp;设备来源:"+(isOld?"利旧设备":"新设备")+ "&emsp;&emsp;&emsp;&emsp;站点编码:"+siteCode +
"&emsp;&emsp;&emsp;&emsp;站点名称:"+siteName);
}
/**
* 给消息加上时间戳
* @param mess
* @return
*/
private String addTimeStamp(String mess){
return " "+mess+" -- "+ DateUtil.date()+"\n";
}
/**
* 输出rabbitmq消息
* @param msg
*/
private void pushRabbitMsg(String msg){
if(msgIndex < 1000){
msgIndex++;
}else {
msgIndex = 0;
msgArea.setText("");
}
msgArea.append(addTimeStamp(msg));
}
/**
* 输出初始化消息
* @param msg
*/
private void pushInitMsg(String msg){
initArea.append(addTimeStamp(msg));
}
/**
* 输出语音播报胡消息
* @param msg
*/
private void pushVoiceMsg(String msg){
if(voiceIndex < 10){
voiceIndex++;
}else {
voiceIndex = 0;
voiceArea.setText("");
}
voiceArea.append(addTimeStamp(msg));
}
/**
* 添加语音播报消息
* @param message
*/
private void handleVoiceMsg(String message){
try {
RabbitMessageBean rb = gson.fromJson(message, RabbitMessageBean.class);
String type = rb.getHeaders().getData().getMessageType();
if(type.equals("call")){ //表示叫号消息
String data = EncryptUtil.base64ToString(rb.getData());
FlowNumBean fnb = gson.fromJson(data, FlowNumBean.class);
flowNumBeanList.putLast(fnb);
if(!isCalling){
isCalling = true;
calling();
}
}
} catch (Exception e) {
pushVoiceMsg("添加语音队列失败:"+message);
log.error("添加语音队列失败:"+message);
}
}
private void test(FlowNumBean flowNumBean){
try {
flowNumBeanList.putLast(flowNumBean);
if(!isCalling){
isCalling = true;
calling();
}
} catch (InterruptedException e) {
pushVoiceMsg("添加语音队列失败:"+gson.toJson(flowNumBean));
log.error("添加语音队列失败:"+e);
}
}
/**
* 读取本地文件配置
*/
private void readConfig(){
File file = new File(configPath);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
log.error( "创建文件失败" ); ;
}
}
Scanner sc = null ;
try
{
sc = new Scanner( file ) ;
String jsonString = sc.next();
ConfigBean jo = gson.fromJson(jsonString, ConfigBean.class);
if(jo != null){
isShow = true;
pushInitMsg("读取配置文件成功");
if(jo.getDeviceId() != null){
deviceId = jo.getDeviceId();
}
if(jo.getHttpIndex() != null){
httpIndex = jo.getHttpIndex();
}
if(jo.getHost() != null){
host = jo.getHost();
}
if(jo.getRegister() != null){
register = jo.getRegister();
}
if(jo.getDeviceInit() != null){
deviceInit = jo.getDeviceInit();
}
if(jo.getDeviceUpdate() != null){
deviceUpdate = jo.getDeviceUpdate();
}
if(jo.getCheckVersion() != null){
checkVersion = jo.getCheckVersion();
}
delayTime = jo.getDelayTime();
english = jo.isEnglish();
zang = jo.isZang();
if(jo.getSpeaker() != null){
speaker = jo.getSpeaker();
}
isOld = jo.isOld();
siteId = jo.getSiteId();
if(jo.getSiteName() != null){
siteName = jo.getSiteName();
}
if(jo.getSiteCode() != null){
siteCode = jo.getSiteCode();
}
}else {
isShow =false;
pushInitMsg("读取配置文件失败->配置文件为空");
log.info( "配置文件为空" ); ;
}
}
catch( Exception e )
{
e.printStackTrace();
}
finally
{
try
{
// log.error( "读写关闭" ) ;
sc.close();
}
catch ( Exception e )
{
}
}
}
private void calling(){
try {
if(flowNumBeanList.size() > 0){
FlowNumBean flowNumBean = flowNumBeanList.takeFirst();
String flownum = flowNumBean.getFlownum();
String windownum = flowNumBean.getWindowfromnum();
//选择发音人
String peple= System.getProperty("user.dir")+"/src/main/resources/sound/"+speaker+"/";
//语音拼接
List<String> audioList = new ArrayList<>();
audioList.add(peple+"qing.mp3");
//拼接排队号
if(flownum.length() > 0){
for (int i = 0; i < flownum.length(); i++) {
audioList.add(peple+flownum.charAt(i)+".mp3");
}
}
audioList.add(peple+"haodao.mp3");
//拼接窗口号
if(speaker.equals("en")){ //发音人为英文发音
if(windownum.length() > 0){
Pattern p = Pattern.compile(".*[a-zA-Z]+.*");
if(p.matcher(windownum).matches()){ //窗口号中有字母
for (int i = 0; i < windownum.length(); i++) {
audioList.add(peple+windownum.charAt(i)+".mp3");
}
}else { //窗口号为纯数字
int num = Integer.parseInt(windownum);
if(num <= 20){
audioList.add(peple+num+".mp3");
}else if(num < 100){
audioList.add(peple+(num/10)+"0.mp3");
if(num%10 > 0){
audioList.add(peple+(num%10)+".mp3");
}
}else if(num <= 100){
audioList.add(peple+"1.mp3");
audioList.add(peple+"bai.mp3");
}
else if (num < 1000){
audioList.add(peple+(num/100)+".mp3");
audioList.add(peple+"bai.mp3");
audioList.add(peple+"and.mp3");
if((num%100)/10 > 0){
if(num%100 <= 20){
audioList.add(peple+num%100+".mp3");
}else {
audioList.add(peple+((num%100)/10)+"0.mp3");
}
}
audioList.add(peple+(num%100%10)+".mp3");
}else {
if(windownum.length() > 0){
for (int i = 0; i < windownum.length(); i++) {
audioList.add(peple+windownum.charAt(i)+".mp3");
}
}
}
}
}
}else {
if(windownum.length() > 0){
Pattern p = Pattern.compile(".*[a-zA-Z]+.*");
if(p.matcher(windownum).matches()){ //窗口号中有字母
for (int i = 0; i < windownum.length(); i++) {
audioList.add(peple+windownum.charAt(i)+".mp3");
}
}else { //窗口号为纯数字
int num = Integer.parseInt(windownum);
if(num < 10){
audioList.add(peple+num+".mp3");
}else if(num < 100){
audioList.add(peple+(num/10)+".mp3");
audioList.add(peple+"shi.mp3");
if(num%10 > 0){
audioList.add(peple+(num%10)+".mp3");
}
}else if (num < 1000){
audioList.add(peple+(num/100)+".mp3");
audioList.add(peple+"bai.mp3");
if((num%100)/10 > 0){
audioList.add(peple+((num%100)/10)+".mp3");
audioList.add(peple+"shi.mp3");
}else {
audioList.add(peple+"0.mp3");
}
audioList.add(peple+(num%100%10)+".mp3");
}else {
if(windownum.length() > 0){
for (int i = 0; i < windownum.length(); i++) {
audioList.add(peple+windownum.charAt(i)+".mp3");
}
}
}
}
}
audioList.add(peple+"haochuangkou.mp3");
}
audioList.add(peple+"kk.mp3");
String url = SpliceMp3Util.heBingMp3(audioList);
if(url != null){
pushVoiceMsg("请"+flownum+"号到"+windownum+"号窗口");
FileInputStream fis = new FileInputStream(url);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
player.play();
// pushVoiceMsg("播放完毕");
isCalling = true;
calling();
}else {
isCalling = true;
calling();
pushVoiceMsg("语音包提取失败:"+url);
}
}else {
isCalling = false;
}
} catch (Exception e) {
//如果异常 则放弃这条语音 继续循环
isCalling = true;
calling();
pushVoiceMsg("语音播报异常:"+e.toString());
}
}
}
...@@ -56,6 +56,8 @@ public class SettingWindow { ...@@ -56,6 +56,8 @@ public class SettingWindow {
static String siteCode = ""; static String siteCode = "";
static String siteName = ""; static String siteName = "";
boolean isShow = false; //判断本地是否有配置文件 有则设置窗口不可见
public static void main(String[] args) { public static void main(String[] args) {
//初始化窗口 //初始化窗口
...@@ -546,7 +548,7 @@ public class SettingWindow { ...@@ -546,7 +548,7 @@ public class SettingWindow {
//设置窗口的位置和大小 //设置窗口的位置和大小
frame.setBounds(660,340,600,400); frame.setBounds(660,340,600,400);
//设置窗口对象不可见 //设置窗口对象不可见
frame.setVisible(true); frame.setVisible(isShow);
frame.addWindowListener(new WindowListener() { frame.addWindowListener(new WindowListener() {
@Override @Override
...@@ -575,6 +577,7 @@ public class SettingWindow { ...@@ -575,6 +577,7 @@ public class SettingWindow {
@Override @Override
public void windowActivated(WindowEvent e) { public void windowActivated(WindowEvent e) {
//界面重现时重新读取配置 //界面重现时重新读取配置
readConfig();
} }
@Override @Override
...@@ -606,6 +609,7 @@ public class SettingWindow { ...@@ -606,6 +609,7 @@ public class SettingWindow {
if(jo != null){ if(jo != null){
isShow = false;
if(jo.getDeviceId() != null){ if(jo.getDeviceId() != null){
deviceId = jo.getDeviceId(); deviceId = jo.getDeviceId();
} }
...@@ -638,6 +642,7 @@ public class SettingWindow { ...@@ -638,6 +642,7 @@ public class SettingWindow {
if(jo.getSpeaker() != null){ if(jo.getSpeaker() != null){
speaker = jo.getSpeaker(); speaker = jo.getSpeaker();
} }
isOld = jo.isOld();
siteId = jo.getSiteId(); siteId = jo.getSiteId();
if(jo.getSiteName() != null){ if(jo.getSiteName() != null){
siteName = jo.getSiteName(); siteName = jo.getSiteName();
...@@ -646,6 +651,7 @@ public class SettingWindow { ...@@ -646,6 +651,7 @@ public class SettingWindow {
siteCode = jo.getSiteCode(); siteCode = jo.getSiteCode();
} }
}else { }else {
isShow = true;
log.info( "配置文件为空" ); ; log.info( "配置文件为空" ); ;
} }
...@@ -686,6 +692,7 @@ public class SettingWindow { ...@@ -686,6 +692,7 @@ public class SettingWindow {
cb.setZang(zang); cb.setZang(zang);
cb.setSpeaker(speaker); cb.setSpeaker(speaker);
cb.setCheckVersion(checkVersion); cb.setCheckVersion(checkVersion);
cb.setOld(isOld);
cb.setSiteId(siteId); cb.setSiteId(siteId);
cb.setSiteCode(siteCode); cb.setSiteCode(siteCode);
cb.setSiteName(siteName); cb.setSiteName(siteName);
......
...@@ -20,8 +20,9 @@ public class ConfigBean { ...@@ -20,8 +20,9 @@ public class ConfigBean {
private boolean english; //英双语 private boolean english; //英双语
private boolean zang; //藏双语 private boolean zang; //藏双语
private String speaker; //播音员 private String speaker; //播音员
private boolean isOld; //是否为利旧设备
private int siteId; // 目前被选中的站点id private int siteId; // 目前被选中的站点id
private String siteCode = ""; private String siteCode; //站点编码
private String siteName = ""; private String siteName; //站点名称
} }
package com.mortals.xhx.tts.bean;
/**
* Created by ZYW on 2022-08-16.
*/
public class DataBean {
private String protocol;
private String messageType;
private String sign;
private String deviceCode;
private String timestamp;
public DataBean(String protocol, String messageType, String sign, String deviceCode, String timestamp) {
this.protocol = protocol;
this.messageType = messageType;
this.sign = sign;
this.deviceCode = deviceCode;
this.timestamp = timestamp;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getMessageType() {
return messageType;
}
public void setMessageType(String messageType) {
this.messageType = messageType;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getDeviceCode() {
return deviceCode;
}
public void setDeviceCode(String deviceCode) {
this.deviceCode = deviceCode;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
}
package com.mortals.xhx.tts.bean;
/**
* Created by ZYW on 2022-05-17.
*/
public class DeviceCodeBean {
private String deviceCode;
private String deviceVersion;
public DeviceCodeBean(String deviceCode, String deviceVersion) {
this.deviceCode = deviceCode;
this.deviceVersion = deviceVersion;
}
public String getDeviceCode() {
return deviceCode;
}
public void setDeviceCode(String deviceCode) {
this.deviceCode = deviceCode;
}
public String getDeviceVersion() {
return deviceVersion;
}
public void setDeviceVersion(String deviceVersion) {
this.deviceVersion = deviceVersion;
}
}
package com.mortals.xhx.tts.bean;
/**
* Created by ZYW on 2023-01-04.
*/
public class FlowNumBean {
private int qid;
private String flownum;
private String windowname;
private String windowfromnum;
private int waitcount;
private int forwaitcount;
private long time; //生成的时间
public FlowNumBean(int qid, String flownum, String windowname, String windowfromnum, long time) {
this.qid = qid;
this.flownum = flownum;
this.windowname = windowname;
this.windowfromnum = windowfromnum;
this.time = time;
}
public int getQid() {
return qid;
}
public void setQid(int qid) {
this.qid = qid;
}
public String getWindowfromnum() {
return windowfromnum;
}
public void setWindowfromnum(String windowfromnum) {
this.windowfromnum = windowfromnum;
}
public int getWaitcount() {
return waitcount;
}
public void setWaitcount(int waitcount) {
this.waitcount = waitcount;
}
public int getForwaitcount() {
return forwaitcount;
}
public void setForwaitcount(int forwaitcount) {
this.forwaitcount = forwaitcount;
}
public String getFlownum() {
return flownum;
}
public void setFlownum(String flownum) {
this.flownum = flownum;
}
public String getWindowname() {
return windowname;
}
public void setWindowname(String windowname) {
this.windowname = windowname;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
}
package com.mortals.xhx.tts.bean;
/**
* Created by ZYW on 2022-08-16.
*/
public class HeadersBean {
private DataBean data;
public HeadersBean(DataBean data) {
this.data = data;
}
public DataBean getData() {
return data;
}
public void setData(DataBean data) {
this.data = data;
}
}
package com.mortals.xhx.tts.bean;
/**
* Created by ZYW on 2022-08-16.
*/
public class RabbitMessageBean {
private String data;
private HeadersBean headers;
private String key;
public RabbitMessageBean(String data, HeadersBean headers, String key) {
this.data = data;
this.headers = headers;
this.key = key;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public HeadersBean getHeaders() {
return headers;
}
public void setHeaders(HeadersBean headers) {
this.headers = headers;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
package com.mortals.xhx.tts.utils;
/**
* @author ZYW
* @date 2024-07-25 11:26
*/
public class Constant {
//加解密相关秘钥
public static int ORDERNUM = 9;
public static String DESKEY ="FZV1D&tr";
public static String AESKEY = "w4*KbUamPdZDnDpG";
}
package com.mortals.xhx.tts.utils;
/**
* Created by ZYW on 2022-05-17.
*/
public class ContentBean {
String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package com.mortals.xhx.tts.utils;
/**
* Created by ZYW on 2022-07-12.
*/
public class DeviceInfoBean {
private Integer productId;
private String productName;
private String productCode;
private String siteCode;
private Integer siteId;
private String siteName;
private Integer source;
private Integer enabled; //设备启用状态 (0.停止,1.启用)
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getSiteCode() {
return siteCode;
}
public void setSiteCode(String siteCode) {
this.siteCode = siteCode;
}
public Integer getSiteId() {
return siteId;
}
public void setSiteId(Integer siteId) {
this.siteId = siteId;
}
public String getSiteName() {
return siteName;
}
public void setSiteName(String siteName) {
this.siteName = siteName;
}
public int getSource() {
return source;
}
public void setSource(Integer source) {
this.source = source;
}
public Integer getEnabled() {
return enabled;
}
public void setEnabled(Integer enabled) {
this.enabled = enabled;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
}
...@@ -4,6 +4,11 @@ import java.io.BufferedReader; ...@@ -4,6 +4,11 @@ import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.UUID; import java.util.UUID;
/** /**
...@@ -51,6 +56,53 @@ public class MacAddressReader { ...@@ -51,6 +56,53 @@ public class MacAddressReader {
} }
/**
* 本机ip
* @return
*/
public static String getInternetIp(){
try {
InetAddress inetAddress = InetAddress.getLocalHost();
String ipAddress = inetAddress.getHostAddress();
return ipAddress;
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
/**
* 获取局域网ip
* @return
*/
public static String getLocalIp(){
try {
// 获取本机的所有网络接口
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
// 确保网络接口已启用
if (networkInterface.isUp()) {
// 确保不是虚拟网络接口
if (!networkInterface.isLoopback()) {
// 遍历接口的所有IP地址
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress inetAddress = addresses.nextElement();
// 确保是IPv4地址
if (inetAddress instanceof java.net.Inet4Address) {
return inetAddress.getHostAddress();
}
}
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return "127.0.0.1";
}
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("MAC Address: " + getMacAddress()); System.out.println("MAC Address: " + getMacAddress());
} }
......
package com.mortals.xhx.tts.utils;
/**
* Created by ZYW on 2022-05-17.
*/
public class RabbitMessBean {
private String downTopicFilter;
private String exchangeName;
private String host;
private String messageTtl;
private String password;
private Integer port;
private String uploadTopicFilter;
private String username;
private String virtualHost;
public String getDownTopicFilter() {
return downTopicFilter;
}
public void setDownTopicFilter(String downTopicFilter) {
this.downTopicFilter = downTopicFilter;
}
public String getExchangeName() {
return exchangeName;
}
public void setExchangeName(String exchangeName) {
this.exchangeName = exchangeName;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getMessageTtl() {
return messageTtl;
}
public void setMessageTtl(String messageTtl) {
this.messageTtl = messageTtl;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public String getUploadTopicFilter() {
return uploadTopicFilter;
}
public void setUploadTopicFilter(String uploadTopicFilter) {
this.uploadTopicFilter = uploadTopicFilter;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getVirtualHost() {
return virtualHost;
}
public void setVirtualHost(String virtualHost) {
this.virtualHost = virtualHost;
}
}
package com.mortals.xhx.tts.utils;
/**
* Created by ZYW on 2022-07-01.
*/
public class ResultRabbitBean {
private RabbitMessBean rabbmitInfo;
private ServiceInfoBean serviceInfo;
private DeviceInfoBean deviceInfo;
public RabbitMessBean getRabbmitInfo() {
return rabbmitInfo;
}
public void setRabbmitInfo(RabbitMessBean rabbmitInfo) {
this.rabbmitInfo = rabbmitInfo;
}
public ServiceInfoBean getServiceInfo() {
return serviceInfo;
}
public void setServiceInfo(ServiceInfoBean serviceInfo) {
this.serviceInfo = serviceInfo;
}
public DeviceInfoBean getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(DeviceInfoBean deviceInfo) {
this.deviceInfo = deviceInfo;
}
}
package com.mortals.xhx.tts.utils;
/**
* Created by ZYW on 2022-07-04.
*/
public class ServiceInfoBean {
private String homeUrl;
private String serverUrl;
private String eventUrl;
public String getHomeUrl() {
return homeUrl;
}
public void setHomeUrl(String homeUrl) {
this.homeUrl = homeUrl;
}
public String getServerUrl() {
return serverUrl;
}
public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
}
public String getEventUrl() {
return eventUrl;
}
public void setEventUrl(String eventUrl) {
this.eventUrl = eventUrl;
}
}
package com.mortals.xhx.tts.utils; package com.mortals.xhx.tts.utils;
import org.aspectj.util.FileUtil;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -199,7 +201,8 @@ public class SpliceMp3Util { ...@@ -199,7 +201,8 @@ public class SpliceMp3Util {
* @throws IOException * @throws IOException
*/ */
public static String heBingMp3(List<String> pathList) throws IOException { public static String heBingMp3(List<String> pathList) throws IOException {
String luJing= "/tmp/"; // String luJing= "/tmp/";
String luJing= "F:\\\\";
File f=new File(luJing); File f=new File(luJing);
f.mkdirs(); f.mkdirs();
//生成处理后的文件 //生成处理后的文件
......
...@@ -46,4 +46,6 @@ siteconfig: ...@@ -46,4 +46,6 @@ siteconfig:
active: active:
active: @profiles.active@ active: @profiles.active@
version: @modelVersion@
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment