From 301dc6362434c9d7b50b113b5eff15852cd46a4a Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 17 Mar 2022 09:22:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=97=A8=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=20ups=E7=94=B5=E6=B1=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E6=94=B9=E6=88=90int?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yutou/nas/Controllers/DoorController.java | 84 +++++++++++++++++++ .../java/com/yutou/nas/NasApplication.java | 2 +- src/main/java/com/yutou/nas/other/tools.java | 2 +- .../java/com/yutou/nas/utils/AudioTools.java | 52 +++++++++++- src/main/java/com/yutou/nas/utils/Tools.java | 8 +- 5 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/yutou/nas/Controllers/DoorController.java diff --git a/src/main/java/com/yutou/nas/Controllers/DoorController.java b/src/main/java/com/yutou/nas/Controllers/DoorController.java new file mode 100644 index 0000000..33ff93b --- /dev/null +++ b/src/main/java/com/yutou/nas/Controllers/DoorController.java @@ -0,0 +1,84 @@ +package com.yutou.nas.Controllers; + +import com.alibaba.fastjson.JSONObject; +import com.yutou.nas.utils.RedisTools; +import com.yutou.nas.utils.StringUtils; +import com.yutou.nas.utils.Tools; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.util.Objects; + +@Controller +public class DoorController { + @RequestMapping("/door/data.do") + @ResponseBody + public JSONObject getData(){ + JSONObject json=new JSONObject(); + String zoom=RedisTools.get("door_zoom"); + if(StringUtils.isEmpty(zoom)){ + zoom="0"; + } + json.put("zoom", Float.parseFloat(zoom)); + json.put("audio",RedisTools.get("door_audio")); + json.put("restart",RedisTools.get("door_reboot")); + json.put("af",RedisTools.get("door_af")); + File file=new File("web"+File.separator+"apk"+File.separator+"door"); + if(file.exists()&& Objects.requireNonNull(file.listFiles()).length!=0){ + JSONObject update=new JSONObject(); + update.put("versionName", Objects.requireNonNull(file.listFiles())[0].getName().replace("app-release-","").replace(".apk","")); + update.put("url","http://192.168.31.88:803/apk/door/"+ Objects.requireNonNull(file.listFiles())[0].getName()); + json.put("update",update); + } + RedisTools.remove("door_audio"); + RedisTools.remove("door_reboot"); + RedisTools.remove("door_af"); + return json; + } + @RequestMapping("/door/zoom.do") + @ResponseBody + public String setZoom(float zoom){ + if(zoom>1){ + zoom=1; + } + if(zoom<0){ + zoom=0; + } + RedisTools.set("door_zoom",zoom+""); + return "1"; + } + @RequestMapping(value="/door/audio.do") + @ResponseBody + public String setAudio(@RequestParam("audio") MultipartFile audio){ + System.out.println("收到音频"); + try { + String path=Tools.createFile("audio",audio,System.currentTimeMillis()+".mp3"); + RedisTools.set("door_audio","http://192.168.31.88:801/"+path); + } catch (Exception e) { + e.printStackTrace(); + } + return "1"; + } + @RequestMapping(value="/door/audio_url.do") + @ResponseBody + public String setAudioUrl(String url){ + RedisTools.set("door_audio",url); + return "1"; + } + @RequestMapping("/door/reboot.do") + @ResponseBody + public String reboot(){ + RedisTools.set("door_reboot","1"); + return "1"; + } + @RequestMapping("/door/af.do") + @ResponseBody + public String af(){ + RedisTools.set("door_af","1"); + return "1"; + } +} diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java index 5619999..ed26baa 100644 --- a/src/main/java/com/yutou/nas/NasApplication.java +++ b/src/main/java/com/yutou/nas/NasApplication.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import; @Import(BTDownloadManager.class) @SpringBootApplication public class NasApplication { - public static final String version="1.2.6"; + public static final String version="1.2.7"; public static void main(String[] args) { SpringApplication.run(NasApplication.class, args); AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir"); diff --git a/src/main/java/com/yutou/nas/other/tools.java b/src/main/java/com/yutou/nas/other/tools.java index 606d770..e6d4877 100644 --- a/src/main/java/com/yutou/nas/other/tools.java +++ b/src/main/java/com/yutou/nas/other/tools.java @@ -153,7 +153,7 @@ public class tools { } @ResponseBody @RequestMapping("/public/getUPSPower.do") - public float getUPSPower(){ + public int getUPSPower(){ return Tools.getSystemUPSPower(); } diff --git a/src/main/java/com/yutou/nas/utils/AudioTools.java b/src/main/java/com/yutou/nas/utils/AudioTools.java index 63f4a99..d61fccb 100644 --- a/src/main/java/com/yutou/nas/utils/AudioTools.java +++ b/src/main/java/com/yutou/nas/utils/AudioTools.java @@ -1,6 +1,9 @@ package com.yutou.nas.utils; import com.iflytek.cloud.speech.*; +import com.yutou.nas.interfaces.ObjectInterface; + +import java.io.File; public class AudioTools { private static boolean init = false; @@ -19,6 +22,7 @@ public class AudioTools { public static void playText(String text) { SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer(); + mss.startSpeaking(text, new SynthesizerListener() { @Override public void onBufferProgress(int progress, int beginPos, int endPos, @@ -26,6 +30,7 @@ public class AudioTools { if (progress == 100) { mss.destroy(); } + } @Override @@ -58,9 +63,54 @@ public class AudioTools { } }); } + public static void getAudio(String text, ObjectInterface objectInterface){ + SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer(); + mss.setParameter(SpeechConstant.VOICE_NAME, "xiaoyu"); + // 设置语速,范围0~100 + mss.setParameter(SpeechConstant.SPEED, "50"); + // 设置语调,范围0~100 + //mss.setParameter(SpeechConstant.PITCH, "50"); + // 设置音量,范围0~100 + mss.setParameter(SpeechConstant.VOLUME, "100"); + + String fileName="html" + File.separator + "audio" + File.separator + System.currentTimeMillis() + ".wav"; + mss.synthesizeToUri( + text, + fileName, + new SynthesizeToUriListener() { + @Override + public void onBufferProgress(int progress) { + System.out.println("progress = " + progress); + if (progress == 100) { + objectInterface.out(fileName); + mss.destroy(); + } + } + + @Override + public void onSynthesizeCompleted(String s, SpeechError speechError) { + System.out.println("s = " + s); + System.out.println("speechError = " + speechError.getErrorDesc()); + } + + @Override + public void onEvent(int i, int i1, int i2, int i3, Object o, Object o1) { + System.out.println("i = " + i + ", i1 = " + i1 + ", i2 = " + i2 + ", i3 = " + i3 + ", o = " + o + ", o1 = " + o1); + } + } + ); + } public static void main(String[] args) { init(); - playText("小爱同学,开灯"); + getAudio("警告!你已经进入监控范围,请立即离开!", new ObjectInterface() { + @Override + public void out(String data) { + super.out(data); + System.out.println(data); + File file=new File(data); + System.out.println(file.getAbsolutePath()); + } + }); } } diff --git a/src/main/java/com/yutou/nas/utils/Tools.java b/src/main/java/com/yutou/nas/utils/Tools.java index 058d888..74b1717 100644 --- a/src/main/java/com/yutou/nas/utils/Tools.java +++ b/src/main/java/com/yutou/nas/utils/Tools.java @@ -30,7 +30,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Tools { - private static float UPSPower=-1.0f; + private static int UPSPower=-1; /** * 设置Cookie * @@ -249,7 +249,7 @@ public class Tools { file.transferTo(saveFile); fileName = URLEncoder.encode(fileName, "UTF-8"); com.yutou.nas.utils.Log.i("上传文件保存路径:" + saveFile.getAbsolutePath()); - return path + fileName; + return path+"/"+ fileName; } public static void download(String url, DownloadInterface downloadInterface) { @@ -378,7 +378,7 @@ public class Tools { return new SimpleDateFormat("yyyy-MM-dd").format(new Date()); } - public static float getSystemUPSPower(){ + public static int getSystemUPSPower(){ AppTools.exec("/sbin/apcaccess |grep BCHARGE ", new ObjectInterface() { @Override public void out(String data) { @@ -387,7 +387,7 @@ public class Tools { Matcher matcher=pattern.matcher(data); if(matcher.find()) { String ups = matcher.group(); - UPSPower=Float.parseFloat(ups); + UPSPower= (int) Float.parseFloat(ups); } } },false,true);