新增门监控控制
ups电池获取单位改成int
This commit is contained in:
@@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user