Browse Source

Merge pull request 'test' (#8) from test into master

Reviewed-on: #8
tags/A.1.2.0.0_20230908_release
bogemail 2 years ago
parent
commit
a48c8e346b
31 changed files with 943 additions and 207 deletions
  1. +17
    -0
      .idea/deploymentTargetDropDown.xml
  2. +2
    -2
      app/build.gradle
  3. BIN
      app/libs/lefaceSDK-multiatt-0814_enc.aar
  4. +2
    -2
      app/release/output-metadata.json
  5. +7
    -4
      app/src/main/java/com/aispeech/nativedemo/DDSService.java
  6. +48
    -11
      app/src/main/java/com/aispeech/nativedemo/MainActivity.java
  7. +19
    -36
      app/src/main/java/com/aispeech/nativedemo/asr/observer/DuiMessageObserver.java
  8. +11
    -3
      app/src/main/java/com/aispeech/nativedemo/camera/CameraController.java
  9. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/config/Config.java
  10. +74
    -15
      app/src/main/java/com/aispeech/nativedemo/config/ConfigManager.java
  11. +19
    -6
      app/src/main/java/com/aispeech/nativedemo/db/ModelBuilder.java
  12. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/db/StrangerDbHelper.java
  13. +28
    -0
      app/src/main/java/com/aispeech/nativedemo/entity/Greeting.java
  14. +4
    -2
      app/src/main/java/com/aispeech/nativedemo/entity/MqttHeartbeat.java
  15. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/entity/PersonInfo.java
  16. +85
    -0
      app/src/main/java/com/aispeech/nativedemo/entity/ProcessEntity.java
  17. +287
    -54
      app/src/main/java/com/aispeech/nativedemo/face/FaceChatMode.java
  18. +7
    -6
      app/src/main/java/com/aispeech/nativedemo/face/FaceManager.java
  19. +79
    -22
      app/src/main/java/com/aispeech/nativedemo/face/FaceReceptionMode.java
  20. +10
    -5
      app/src/main/java/com/aispeech/nativedemo/mqtt/MqttConfig.java
  21. +5
    -5
      app/src/main/java/com/aispeech/nativedemo/mqtt/MqttManager.java
  22. +4
    -2
      app/src/main/java/com/aispeech/nativedemo/mqtt/MqttReply.java
  23. +3
    -1
      app/src/main/java/com/aispeech/nativedemo/network/ws/DigiWebSocketServer.java
  24. +54
    -11
      app/src/main/java/com/aispeech/nativedemo/network/ws/MessageUtils.java
  25. +11
    -9
      app/src/main/java/com/aispeech/nativedemo/shape/ShapeManager.java
  26. +4
    -3
      app/src/main/java/com/aispeech/nativedemo/upload/UploadManager.java
  27. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/utils/ConfigClass.java
  28. +37
    -0
      app/src/main/java/com/aispeech/nativedemo/utils/StatusUtils.java
  29. +108
    -0
      app/src/main/java/com/aispeech/nativedemo/utils/Utils.java
  30. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/widget/AlertWindowView.java
  31. +13
    -3
      app/src/main/res/layout/activity_main.xml

+ 17
- 0
.idea/deploymentTargetDropDown.xml View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="93c5f6c31a1255cd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-09-01T12:35:30.709171900Z" />
</component>
</project>

+ 2
- 2
app/build.gradle View File

@@ -8,8 +8,8 @@ android {
applicationId "com.aispeech.nativedemo"
minSdkVersion 26
targetSdkVersion 30
versionCode 2
versionName "0.9"
versionCode 3
versionName "A.1.0.6.5_20230908_base"

sourceSets {
main { //这个配置是必须的,如果你的so文件放在了libs/armeabi/下,则下面srcDir = libs即可


BIN
app/libs/lefaceSDK-multiatt-0323_enc.aar → app/libs/lefaceSDK-multiatt-0814_enc.aar View File


+ 2
- 2
app/release/output-metadata.json View File

@@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 2,
"versionName": "0.9",
"versionCode": 3,
"versionName": "A.1.0.6.5_20230908_base",
"outputFile": "app-release.apk"
}
],


+ 7
- 4
app/src/main/java/com/aispeech/nativedemo/DDSService.java View File

@@ -30,6 +30,7 @@ import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.mqtt.MqttManager;
import com.aispeech.nativedemo.ui.LauncherActivity;
import com.aispeech.nativedemo.config.Config;
import com.aispeech.nativedemo.utils.StatusUtils;

import java.io.File;
import java.io.IOException;
@@ -134,7 +135,9 @@ public class DDSService extends Service {
} else{
Logger.e("思必驰++++++++++++++++++++");
}
// DDS.getInstance().setAudioDebug(true);
if(!Config.CURRENT_URL.equals(Config.PROD_BASE_URL)){
DDS.getInstance().setAudioDebug(true);
}
}

@Override
@@ -222,8 +225,8 @@ public class DDSService extends Service {
config.addConfig(DDSConfig.K_API_KEY, "d797bc5edc9778f7d0ca8242643fa41a"); // 产品授权秘钥,服务端生成,用于产品授权 -- 必填
// config.addConfig(DDSConfig.K_DEVICE_ID, getDeviceId(getApplicationContext()));//填入唯一的deviceId -- 选填
// config.addConfig(DDSConfig.K_DEVICE_NAME, getDeviceId(getApplicationContext()));//填入唯一的deviceId -- 选填
config.addConfig(DDSConfig.K_DEVICE_ID, Build.SERIAL);//填入唯一的deviceId -- 选填
config.addConfig(DDSConfig.K_DEVICE_NAME, Build.SERIAL);//填入唯一的deviceId -- 选填
config.addConfig(DDSConfig.K_DEVICE_ID, StatusUtils.getSerialNumber());//填入唯一的deviceId -- 选填
config.addConfig(DDSConfig.K_DEVICE_NAME, StatusUtils.getSerialNumber());//填入唯一的deviceId -- 选填
// config.addConfig(DDSConfig.K_AUDIO_FOCUS_MODE, "external");//填入唯一的deviceId -- 选填

config.addConfig(DDSConfig.K_ASR_ENABLE_PUNCTUATION, "true");
@@ -321,7 +324,7 @@ public class DDSService extends Service {
} catch (Exception e) {
e.printStackTrace();
}
String serial = Build.SERIAL;
String serial = StatusUtils.getSerialNumber();
String uuid;
if (TextUtils.isEmpty(imei)) {
imei = "unkown";


+ 48
- 11
app/src/main/java/com/aispeech/nativedemo/MainActivity.java View File

@@ -128,6 +128,7 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa
private Button startClient;
private Bitmap textureBitmap;
private WebView mWebView;
private WebView mWebView2;
public static MainActivity instance;

private String HANDLE_THREAD_NAME = "CameraBackgroundThread";
@@ -228,11 +229,10 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa
// File file = new File(getExternalFilesDir(null).getAbsolutePath() + "/update/" + getPackageName() + ".apk");
// AppUtils.installApk(MainActivity.this, file);

String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath()
+"/Android/data/com.aispeech.nativedemo/files/asrCache/" + "16k_10.pcm";
File file = new File(dirPath);
if(file.exists()){
IatManager.getInstance().executeStream(dirPath);
try {
DDS.getInstance().getAgent().sendText("你好,我是小智");
} catch (DDSNotInitCompleteException e) {
throw new RuntimeException(e);
}
}
});
@@ -347,6 +347,7 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa
if(mWebView.getBackground() != null){
mWebView.getBackground().setAlpha(0);
}
mWebView.setWebViewClient();
//声明WebSettings子类
WebSettings webSettings = mWebView.getSettings();

@@ -369,8 +370,39 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa
webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
webSettings.setDomStorageEnabled(true);

// mWebView.loadUrl("http://192.168.10.244:48088");
webSettings.setMediaPlaybackRequiresUserGesture(false);

// mWebView.loadUrl("http://192.168.137.1");
//
// mWebView2 = findViewById(R.id.webview2);
// mWebView2.setBackgroundColor(0);
// if(mWebView2.getBackground() != null){
// mWebView2.getBackground().setAlpha(0);
// }
// //声明WebSettings子类
// webSettings = mWebView2.getSettings();
//
// //如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
// webSettings.setJavaScriptEnabled(true);
//
// //设置自适应屏幕,两者合用
// webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
// webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
//
// //缩放操作
// webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
// webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放
// webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
//
// //其他细节操作
// webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
// webSettings.setAllowFileAccess(true); //设置可以访问文件
// webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
// webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
// webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
// webSettings.setDomStorageEnabled(true);
//
// mWebView2.loadUrl("http://192.168.10.244:48089?devId=93c5f6c31a1255cd");
}

private WebSocketManager mWSManager;
@@ -543,28 +575,33 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa
try {
Log.e(TAG, "-----------------detect face----------------");
textureBitmap = mTextureView.getBitmap();

//删除过期人员
FaceChatMode.deleteExpirePerson();
List<MultiAtt> results = FaceChatMode.detectMultiAtt(textureBitmap);
if (results != null && results.size() > 0) {
//过滤相同人物
FaceChatMode.filterPersonForFeatExtract(results, textureBitmap);
//删除过期人员
FaceChatMode.deleteExpirePerson();
boolean isContinue = FaceChatMode.featExtract(results, textureBitmap);
if(isContinue){
// if(isInitComplete){
// DDSManager.getInstance().wakeUpDDSDialog();
// }
FaceChatMode.confirmCurrentPerson(textureBitmap);
// FaceChatMode.confirmCurrentPerson();
}
// if(!mFaceManager.hasPerson()){
// DDSManager.getInstance().stopDDSDialog();
// }
}
if(System.currentTimeMillis() - FaceChatMode.mInterval > 500){
FaceChatMode.confirmCurrentPerson();
FaceChatMode.mInterval = System.currentTimeMillis();
}
Log.e(TAG, "---------------thread execute over-------------");
loopDetect();
} catch (Exception e) {
e.printStackTrace();
}
loopDetect();
}
};



+ 19
- 36
app/src/main/java/com/aispeech/nativedemo/asr/observer/DuiMessageObserver.java View File

@@ -66,59 +66,42 @@ public class DuiMessageObserver implements MessageObserver {
@Override
public JSONObject onDMTaskResult(JSONObject jsonObject, Type type) {
if(type == Type.DM_OUTPUT){
String sessionId = jsonObject.optString("sessionId");
String display = jsonObject.optString("display");
String nlg = jsonObject.optString("nlg");
String dmInput = jsonObject.optString("dmInput");
Log.e(Tag, display);
Log.e(Tag, nlg);
String readText = nlg;
// if(FaceManager.getInstance(DuiApplication.getContext()).hasPerson()) {
if (JSONUtils.isJson(display)) {
readText = MessageUtils.sendSkill(display, dmInput);
try {
jsonObject.put("nlg", "");
jsonObject.put("display", "");
MessageUtils.sendTtsNlpText(readText);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
try {
jsonObject.put("nlg", "");
jsonObject.put("display", "");
MessageUtils.sendTtsNlpText(readText);
} catch (JSONException e) {
e.printStackTrace();
}
}
// } else{
// if (JSONUtils.isJson(display)) {
// readText = MessageUtils.sendSkill(sessionId, display, dmInput);
// try {
// jsonObject.put("nlg", "");
// jsonObject.put("display", "");
// } catch (JSONException e) {
// throw new RuntimeException(e);
// }
// }
// } else{
// try {
// jsonObject.put("nlg", "");
// jsonObject.put("display", "");
// jsonObject.put("display", "");
// MessageUtils.sendTtsNlpText(readText);
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
// if(!TextUtils.isEmpty(readText)){
// } else {
// try {
// JSONObject jo = new JSONObject();
// jo.put("type", "djTtsText");
// jo.put("data", readText);
// WebSocketManager.getInstance(MainActivity.instance).sendMsg(jo.toString());
// jsonObject.put("nlg", "");
// jsonObject.put("display", "");
// jsonObject.put("display", "");
// MessageUtils.sendTtsNlpText(readText);
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
if (JSONUtils.isJson(display)) {
MessageUtils.sendSkill(sessionId, display, dmInput);
} else {
MessageUtils.sendNlpResult(sessionId, display, dmInput);
}
try {
jsonObject.put("nlg", "");
jsonObject.put("display", "");
} catch (JSONException e) {
e.printStackTrace();
}
}
return jsonObject;
}


+ 11
- 3
app/src/main/java/com/aispeech/nativedemo/camera/CameraController.java View File

@@ -32,7 +32,9 @@ import android.view.TextureView;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;

import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.utils.BitmapUtil;
import com.aispeech.nativedemo.utils.CommandExecution;

import java.nio.ByteBuffer;
import java.util.Arrays;
@@ -86,6 +88,12 @@ public class CameraController implements ICamera{

@Override
public void onError(@NonNull CameraDevice camera, int error) {
Logger.e("camera error " + error);
if (error == ERROR_MAX_CAMERAS_IN_USE) {
String[] commons = new String[1];
commons[0] = "reboot";
CommandExecution.execCommand(commons, true);
}
camera.close();
}
};
@@ -183,9 +191,9 @@ public class CameraController implements ICamera{
//描述相机设备的属性类
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
//获取是前置还是后置摄像头
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
// Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
//使用后置摄像头
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {//LENS_FACING_EXTERNAL
// if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {//LENS_FACING_EXTERNAL
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map != null) {
// Size[] outputSizes = map.getOutputSizes(SurfaceTexture.class);
@@ -211,7 +219,7 @@ public class CameraController implements ICamera{
Log.e(TAG, "screen's size: width-" + size.x + ",height-" + size.y);
mCameraId = cameraId;
imageReaderView.setCameraId(cameraId);
}
// }
}
}
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {


+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/config/Config.java View File

@@ -9,7 +9,7 @@ public class Config {
public static final String PROD_BASE_URL= "http://123.57.75.177:8080/";
public static final String TEST_BASE_URL= "http://39.107.77.235:8080/";
public static final String DEV_BASE_URL= "http://192.168.10.244:8080/";
public static final String CURRENT_URL= PROD_BASE_URL;
public static final String CURRENT_URL= TEST_BASE_URL;

public static final long ONE_SECOND = 1000L;
public static final long ONE_MINUTE = 60 * ONE_SECOND;


+ 74
- 15
app/src/main/java/com/aispeech/nativedemo/config/ConfigManager.java View File

@@ -2,7 +2,6 @@ package com.aispeech.nativedemo.config;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.util.Log;

import com.aispeech.nativedemo.DuiApplication;
@@ -27,12 +26,14 @@ import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.network.ws.MessageUtils;
import com.aispeech.nativedemo.network.ws.WebSocketManager;
import com.aispeech.nativedemo.utils.HttpUtil;
import com.aispeech.nativedemo.utils.StatusUtils;
import com.aispeech.nativedemo.utils.Utils;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
@@ -79,7 +80,7 @@ public class ConfigManager {
}

private void heartbeat() {
// DigiNetworkManager.run().heartbeat("123456", Build.SERIAL, "10000", "123456", "administrator")
// DigiNetworkManager.run().heartbeat("123456", StatusUtils.getSerialNumber(), "10000", "123456", "administrator")
// .asyncExecute(new DigiServiceCallBack<HeartbeatResponse>() {
// @Override
// public void onResponse(DigiServiceResult<HeartbeatResponse> response) {
@@ -104,7 +105,7 @@ public class ConfigManager {

HashMap<String, String> map = new HashMap<>();
map.put("id", "123456");
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("timestamp", "10000");
map.put("sign", "123456");
map.put("enterpriseName", "administrator");
@@ -140,7 +141,7 @@ public class ConfigManager {
getReception();
}
if((data & 0x10000) > 0){
getConfig();
}
} else {
onFail(obj.getString("msg"));
@@ -162,7 +163,7 @@ public class ConfigManager {
private void getUserInfo() {
HashMap<String, String> map = new HashMap<>();
map.put("id", "123456");
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("type", "0");
map.put("sign", "123456");
map.put("enterpriseName", "administrator");
@@ -236,7 +237,7 @@ public class ConfigManager {
private void getSkill() {
HashMap<String, String> map = new HashMap<>();
map.put("id", "123456");
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("type", "1");
map.put("sign", "123456");
map.put("enterpriseName", "administrator");
@@ -294,7 +295,7 @@ public class ConfigManager {
private void getModel() {
HashMap<String, String> map = new HashMap<>();
map.put("id", "123456");
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("type", "2");
map.put("sign", "123456");
map.put("enterpriseName", "administrator");
@@ -313,7 +314,7 @@ public class ConfigManager {
code = obj.getInt("code");
}
if (code == 200) {
// MessageUtils.sendMessage("模型:" + success);
MessageUtils.sendMessage("模型:" + success);
if (obj.has("data")) {
JSONObject jsonObject = obj.getJSONObject("data");
Model model = new Model();
@@ -342,8 +343,14 @@ public class ConfigManager {
model.workdayHour = new WorkDayHour().create(jsonObject.optJSONObject("workdayHour"));
}
if(jsonObject.has("broadcast")){
Broadcast broadcast = new Broadcast().create(jsonObject.optJSONObject("broadcast"));
MessageUtils.sendBroadcast(broadcast.toString());
JSONObject object = jsonObject.getJSONObject("broadcast");
// List<Broadcast> broadcasts = new ArrayList<>();
// for (int i = 0; i < array.length(); i++) {
// JSONObject broadcastObj = array.getJSONObject(i);
// Broadcast broadcast = new Broadcast().create(broadcastObj);
// broadcasts.add(broadcast);
// }
MessageUtils.sendBroadcast(object.toString());
}
ModelDbHelper.getInstance().add(model);
if (obj.has("timestamp")) {
@@ -361,7 +368,7 @@ public class ConfigManager {

@Override
public void onFail(String error) {
Log.e(TAG, "getModel = " + error);
Logger.e("getModel = "+error);
}
});
}
@@ -369,7 +376,7 @@ public class ConfigManager {
private void getReception() {
HashMap<String, String> map = new HashMap<>();
map.put("id", "123456");
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("type", "3");
map.put("sign", "123456");
map.put("enterpriseName", "administrator");
@@ -394,9 +401,9 @@ public class ConfigManager {
Reception reception = new Reception();
reception.create(object);
ReceptionDbHelper.getInstance().add(reception);
if(IdentityMode.MODE_CURRENT.equals(IdentityMode.MODE_RECEPTION)){
FaceReceptionMode.mReception = reception;
}
// if(IdentityMode.MODE_CURRENT.equals(IdentityMode.MODE_RECEPTION)){
// FaceReceptionMode.mReception = reception;
// }
// if (obj.has("timestamp")) {
// mUserTimeStamp = obj.optLong("timestamp");
// }
@@ -417,7 +424,59 @@ public class ConfigManager {
});
}

private void getConfig() {
HashMap<String, String> map = new HashMap<>();
map.put("id", "123456");
map.put("devId", StatusUtils.getSerialNumber());
map.put("type", "4");
map.put("sign", "123456");
map.put("enterpriseName", "administrator");
map.put("timestamp", "1");
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());
HttpUtil.post(Config.CURRENT_URL + "message/api/update", requestBody, null, new HttpUtil.HttpCallback<String>() {

@Override
public void onSuccess(String success) {
Log.e(TAG, "getReception = " + success);
try {
JSONTokener t = new JSONTokener(success);
JSONObject obj = (JSONObject) t.nextValue();
int code = 0;
if (obj.has("code")) {
code = obj.getInt("code");
}
if (code == 200) {
// MessageUtils.sendMessage("接待任务:" + success);
if (obj.has("data")) {
JSONObject object = obj.getJSONObject("data");
if (object.has("msg")) {
JSONObject config = object.getJSONObject("msg");
MessageUtils.sendConfig(config.toString());
}
}
} else {
onFail(obj.getString("msg"));
}
} catch (Exception e) {
e.printStackTrace();
onFail(e.getMessage());
}
}

@Override
public void onFail(String error) {
Log.e(TAG, "getReception = " + error);
}
});
}

private void checkServiceStatus(){
boolean survive = Utils.isProcessAlive("com.lecooai.lewatchdog");//packageName
Log.e(TAG, "进程是存活: " + survive + ", PID: " + survive);
if(!survive){
Utils.startWatchdogActivity();
}

boolean isWork = false;
ActivityManager am = (ActivityManager) DuiApplication.getContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> list = am.getRunningServices(40);


+ 19
- 6
app/src/main/java/com/aispeech/nativedemo/db/ModelBuilder.java View File

@@ -2,6 +2,7 @@ package com.aispeech.nativedemo.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.text.TextUtils;

import com.aispeech.nativedemo.entity.Background;
import com.aispeech.nativedemo.entity.Emp;
@@ -31,11 +32,17 @@ public class ModelBuilder implements DatabaseBuilder<Model>{
// String icon = (query.getString(query.getColumnIndex("icon")));
// model.icon = new Icon().create(new JSONObject(icon));
String screenOff = (query.getString(query.getColumnIndex("screen_off")));
model.screenOff = new ScreenOff().create(new JSONObject(screenOff));
if(!TextUtils.isEmpty(screenOff)){
model.screenOff = new ScreenOff().create(new JSONObject(screenOff));
}
String workTime = (query.getString(query.getColumnIndex("work_time")));
model.workTime = new WorkTime().create(new JSONObject(workTime));
if(!TextUtils.isEmpty(workTime)){
model.workTime = new WorkTime().create(new JSONObject(workTime));
}
String workdayHour = (query.getString(query.getColumnIndex("work_day_hour")));
model.workdayHour = new WorkDayHour().create(new JSONObject(workdayHour));
if(!TextUtils.isEmpty(workdayHour)){
model.workdayHour = new WorkDayHour().create(new JSONObject(workdayHour));
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
@@ -52,9 +59,15 @@ public class ModelBuilder implements DatabaseBuilder<Model>{
contentValues.put("update_time",model.updateTime);
// contentValues.put("background",model.background.toString());
// contentValues.put("icon",model.icon.toString());
contentValues.put("screen_off",model.screenOff.toString());
contentValues.put("work_time",model.workTime.toString());
contentValues.put("work_day_hour",model.workdayHour.toString());
if(model.screenOff != null){
contentValues.put("screen_off",model.screenOff.toString());
}
if(model.workTime != null) {
contentValues.put("work_time", model.workTime.toString());
}
if(model.workdayHour != null) {
contentValues.put("work_day_hour",model.workdayHour.toString());
}
return contentValues;
}
}

+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/db/StrangerDbHelper.java View File

@@ -98,7 +98,7 @@ public class StrangerDbHelper extends IDbHelper<Stranger> {
Cursor cursor = null;
try {
database = DatabaseImpl.getDatabase().getDb();
cursor = database.rawQuery("select * from new_user_faces where eid = ?",
cursor = database.rawQuery("select * from new_user_faces where user_id = ?",
new String[]{String.valueOf(stranger.id)});
return cursor.getCount() > 0;
} catch (Exception e) {


+ 28
- 0
app/src/main/java/com/aispeech/nativedemo/entity/Greeting.java View File

@@ -0,0 +1,28 @@
package com.aispeech.nativedemo.entity;

import androidx.annotation.NonNull;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

public class Greeting implements Serializable {
public String userId;
public int trackId;
public long greetingTime;

@NonNull
@Override
public String toString() {
JSONObject object = new JSONObject();
try {
object.put("userId", userId);
object.put("trackId", trackId);
object.put("greetingTime", greetingTime);
} catch (JSONException e) {
throw new RuntimeException(e);
}
return object.toString();
}
}

+ 4
- 2
app/src/main/java/com/aispeech/nativedemo/entity/MqttHeartbeat.java View File

@@ -5,6 +5,8 @@ import android.os.SystemClock;

import androidx.annotation.NonNull;

import com.aispeech.nativedemo.utils.StatusUtils;

import org.json.JSONException;
import org.json.JSONObject;

@@ -34,7 +36,7 @@ public class MqttHeartbeat implements Serializable {
public String sign;

public void create() {
devId = Build.SERIAL;
devId = StatusUtils.getSerialNumber();
timestamp = SystemClock.uptimeMillis() + "";
cpuinfo_max_freq = "1";
cpuinfo_min_freq = "1";
@@ -46,7 +48,7 @@ public class MqttHeartbeat implements Serializable {
JSONObject hb = new JSONObject();
try {
hb.put("id", id);
hb.put("devId", Build.SERIAL);
hb.put("devId", StatusUtils.getSerialNumber());
hb.put("timestamp", SystemClock.uptimeMillis());
hb.put("cpuinfo_max_freq", "1");
hb.put("cpuinfo_min_freq", "1");


+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/entity/PersonInfo.java View File

@@ -25,7 +25,7 @@ public class PersonInfo {
public float[] dfeatures;

public PersonInfo(){
this.startTime = this.updateTime = System.currentTimeMillis();
}

public PersonInfo(String id, String name, String tag, int times, int gender, int trackId, float score, MultiAtt att){


+ 85
- 0
app/src/main/java/com/aispeech/nativedemo/entity/ProcessEntity.java View File

@@ -0,0 +1,85 @@
package com.aispeech.nativedemo.entity;

public class ProcessEntity {
String USER;
String PID;
String PPID;
String VSZ;
String RSS;
String WCHAN;
String ADDR;
String S;
String NAME;

public String getUSER() {
return USER;
}

public void setUSER(String USER) {
this.USER = USER;
}

public String getPID() {
return PID;
}

public void setPID(String PID) {
this.PID = PID;
}

public String getPPID() {
return PPID;
}

public void setPPID(String PPID) {
this.PPID = PPID;
}

public String getVSZ() {
return VSZ;
}

public void setVSZ(String VSZ) {
this.VSZ = VSZ;
}

public String getRSS() {
return RSS;
}

public void setRSS(String RSS) {
this.RSS = RSS;
}

public String getWCHAN() {
return WCHAN;
}

public void setWCHAN(String WCHAN) {
this.WCHAN = WCHAN;
}

public String getADDR() {
return ADDR;
}

public void setADDR(String ADDR) {
this.ADDR = ADDR;
}

public String getS() {
return S;
}

public void setS(String s) {
S = s;
}

public String getNAME() {
return NAME;
}

public void setNAME(String NAME) {
this.NAME = NAME;
}
}

+ 287
- 54
app/src/main/java/com/aispeech/nativedemo/face/FaceChatMode.java View File

@@ -1,7 +1,6 @@
package com.aispeech.nativedemo.face;

import android.graphics.Bitmap;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;

@@ -13,6 +12,7 @@ import com.aispeech.nativedemo.db.ModelDbHelper;
import com.aispeech.nativedemo.db.SkillDbHelper;
import com.aispeech.nativedemo.db.StrangerDbHelper;
import com.aispeech.nativedemo.entity.Emp;
import com.aispeech.nativedemo.entity.Greeting;
import com.aispeech.nativedemo.entity.Model;
import com.aispeech.nativedemo.entity.PersonInfo;
import com.aispeech.nativedemo.entity.Skill;
@@ -21,6 +21,7 @@ import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.network.ws.MessageUtils;
import com.aispeech.nativedemo.utils.BmpCompressUtils;
import com.aispeech.nativedemo.utils.HttpUtil;
import com.aispeech.nativedemo.utils.StatusUtils;
import com.aispeech.nativedemo.utils.Utils;
import com.lenovo.lefacesdk.IdentificationResult;
import com.lenovo.lefacesdk.MultiAtt;
@@ -39,6 +40,8 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Stream;
@@ -51,6 +54,8 @@ public class FaceChatMode {
private static final String TAG = "FaceChatMode";
private static Map<String, PersonInfo> mPersons = new HashMap<>();
private static Map<Integer, PersonInfo> mUndeterminedPersons = new HashMap<>();
private static Map<String, Greeting> mGreetingPersons = new HashMap<>();
private static Map<Integer, Greeting> mUndeterminedGreetingPersons = new HashMap<>();
private static PersonInfo mSelectPerson = null;
private static boolean isContainSelectPerson = false;
public static long mInterval = 0;
@@ -82,9 +87,11 @@ public class FaceChatMode {
if(mUndeterminedPersons.containsKey(person.trackId)){
PersonInfo origin = mUndeterminedPersons.get(person.trackId);
origin.updateTime = System.currentTimeMillis();
origin.result = person.result;
origin.faceWidth = person.faceWidth;
origin.bitmap = person.bitmap;
if(person.result.hd_fa > 0 && person.result.fa_quality > origin.result.fa_quality){
origin.result = person.result;
origin.faceWidth = person.faceWidth;
origin.bitmap = person.bitmap;
}
mUndeterminedPersons.put(person.trackId, origin);
} else{
mUndeterminedPersons.put(person.trackId, person);
@@ -94,9 +101,11 @@ public class FaceChatMode {
if(mPersons.containsKey(person.id)){
PersonInfo origin = mPersons.get(person.id);
origin.updateTime = System.currentTimeMillis();
origin.result = person.result;
origin.faceWidth = person.faceWidth;
origin.bitmap = person.bitmap;
if(person.result.hd_fa > 0 && person.result.fa_quality > origin.result.fa_quality){
origin.result = person.result;
origin.faceWidth = person.faceWidth;
origin.bitmap = person.bitmap;
}
mPersons.put(person.id, origin);
} else{
mPersons.put(person.id, person);
@@ -109,11 +118,8 @@ public class FaceChatMode {
}
}
}
if(System.currentTimeMillis() - mInterval < 1000){
return false;
}
Logger.e("djTtsTime-收集数据结束:" + System.currentTimeMillis());
// sendStrangerToServer();
mInterval = System.currentTimeMillis();
return true;
}

@@ -123,21 +129,27 @@ public class FaceChatMode {
filterUndeterminedFace(results, textureBitmap);
}

public static void confirmCurrentPerson(Bitmap textureBitmap){
public static void confirmCurrentPerson(){
if(mPersons.size() == 0 && mUndeterminedPersons.size() == 0){
return;
}

//打招呼
clearGreeting();
greeting();

//优先交互权
//第二阶段 判断当前人
if(mSelectPerson == null){
if(mPersons.size() == 0){
if(mUndeterminedPersons.size() > 0){
//选择未确定脸大的人
mSelectPerson = selectUnknownMaxFacePerson(mUndeterminedPersons);
sendMsgAndLog(textureBitmap);
sendMsgAndLog();
}
return;
} else{
mSelectPerson = selectKnownMaxTagAndFacePerson();
sendMsgAndLog();
}
return;
}
@@ -169,13 +181,12 @@ public class FaceChatMode {
int maxTag = selectPersonMaxTag(candidatesKnown);
mSelectPerson = filterHighLevelAndMaxFacePerson(candidatesKnown, maxTag);
}
sendMsgAndLog(textureBitmap);
sendMsgAndLog();
}

private static PersonInfo selectKnownMaxTagAndFacePerson(){
int maxTag = selectPersonMaxTag(mPersons);
return filterHighLevelAndMaxFacePerson(mPersons, maxTag);
// sendMsgAndLog(textureBitmap);
}

private static List<PersonInfo> mCandidates = new ArrayList<>();
@@ -260,9 +271,11 @@ public class FaceChatMode {
PersonInfo value = entry.getValue();
if (att.track_id == value.trackId) {
value.updateTime = System.currentTimeMillis();
value.faceWidth = att.fa_w;
value.result = att;
value.bitmap = textureBitmap;
if(att.hd_fa > 0 && att.fa_quality > value.result.fa_quality){
value.faceWidth = att.fa_w;
value.result = att;
value.bitmap = textureBitmap;
}
mPersons.put(key, value);
it.remove();
}
@@ -303,9 +316,11 @@ public class FaceChatMode {
PersonInfo stranger = mUndeterminedPersons.get(att.track_id);
if(stranger.id.equals("-2")){
stranger.updateTime = System.currentTimeMillis();
stranger.faceWidth = att.fa_w;
stranger.result = att;
stranger.bitmap = textureBitmap;
if(att.hd_fa > 0 && att.fa_quality > stranger.result.fa_quality){
stranger.faceWidth = att.fa_w;
stranger.result = att;
stranger.bitmap = textureBitmap;
}
mUndeterminedPersons.put(att.track_id, stranger);
it.remove();
return;
@@ -318,17 +333,18 @@ public class FaceChatMode {
message.name = "";
message.tag = "6";
message.trackId = att.track_id;
message.startTime = System.currentTimeMillis();
message.result = att;
message.faceWidth = att.fa_w;
message.bitmap = textureBitmap;
mUndeterminedPersons.put(att.track_id, message);
} else{
PersonInfo message = mUndeterminedPersons.get(att.track_id);
message.updateTime = System.currentTimeMillis();
message.faceWidth = att.fa_w;
message.result = att;
message.bitmap = textureBitmap;
message.updateTime = System.currentTimeMillis();
if(att.hd_fa > 0 && att.fa_quality > message.result.fa_quality){
message.faceWidth = att.fa_w;
message.result = att;
message.bitmap = textureBitmap;
}
mUndeterminedPersons.put(att.track_id, message);
}
it.remove();
@@ -337,7 +353,7 @@ public class FaceChatMode {
}

private static final int PERSON_EXPIRE_TIME = 5000; //人物过期时间
private static final int UNKNOWN_PERSON_EXPIRE_TIME = 1500;
private static final int UNKNOWN_PERSON_EXPIRE_TIME = 3000;
private static final int FACE_DIFF = 70;
private static final int CANDIDATE_STAY_TIME = 3000;

@@ -403,7 +419,7 @@ public class FaceChatMode {
private static String lastUserID;
private static long nextLogTime;

private static void sendMsgAndLog(Bitmap textureBitmap){
private static void sendMsgAndLog(){
if(mSelectPerson == null){
return;
}
@@ -418,12 +434,12 @@ public class FaceChatMode {
if (!sendId.equals(lastUserID)) {
lastUserID = sendId;
nextLogTime = System.currentTimeMillis();
sendLog(isStranger, sendId, mSelectPerson.tag, (mSelectPerson.score), BmpCompressUtils.getBytesByBitmap(Utils.CompressBmp(textureBitmap, mSelectPerson.result), 50, Bitmap.CompressFormat.JPEG));
sendLog(isStranger, sendId, mSelectPerson.tag, (mSelectPerson.score), BmpCompressUtils.getBytesByBitmap(Utils.CompressBmp(mSelectPerson.bitmap, mSelectPerson.result), 50, Bitmap.CompressFormat.JPEG));
} else {
if (System.currentTimeMillis() - nextLogTime > 60000) {
lastUserID = sendId;
nextLogTime = System.currentTimeMillis();
sendLog(isStranger, sendId, mSelectPerson.tag, (mSelectPerson.score), BmpCompressUtils.getBytesByBitmap(Utils.CompressBmp(textureBitmap, mSelectPerson.result), 50, Bitmap.CompressFormat.JPEG));
sendLog(isStranger, sendId, mSelectPerson.tag, (mSelectPerson.score), BmpCompressUtils.getBytesByBitmap(Utils.CompressBmp(mSelectPerson.bitmap, mSelectPerson.result), 50, Bitmap.CompressFormat.JPEG));
}
}
sendStrangerToServer();
@@ -459,7 +475,7 @@ public class FaceChatMode {
name = !TextUtils.isEmpty(emp.nickName) ? emp.nickName : emp.name; //两个名称都传给H5
gender = emp.gender == 0 ? (int) result.bd_gender : emp.gender;
tag = emp.typeId +"";
// Logger.e(TAG, "------------识别到人:" + name + "-------------");
Logger.e("djTtsTime-识别到人:" + name + "-------------");
Set<String> strings = Utils.userLogs.keySet();
if (strings.contains(id)) {
times = 1;
@@ -544,7 +560,110 @@ public class FaceChatMode {
SimpleDateFormat spTime = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");//yyyy-MM-dd/HH:mm:ss HH24 hh12
String sT = spTime.format(date);
String sendingMsg = obj.toString();
Logger.e(sT + ":发送消息到H5: " + sendingMsg + "/");
// Logger.e(sT + ":发送消息到H5: " + sendingMsg + "/");
Logger.e("djTtsTime-给H5发消息打招呼:" + System.currentTimeMillis());
MessageUtils.sendMessage(sendingMsg);
} catch (JSONException e) {
e.printStackTrace();
}
}

public static void greeting(){
for (Map.Entry<String, PersonInfo> entry : mPersons.entrySet()) {
if(!mGreetingPersons.containsKey(entry.getKey())){
String uid = entry.getKey();
sendGreeting(entry.getValue());
Greeting greeting = new Greeting();
greeting.userId = uid;
greeting.greetingTime = System.currentTimeMillis();
mGreetingPersons.put(entry.getKey(), greeting);
return;
}
}
for (Map.Entry<Integer, PersonInfo> entry : mUndeterminedPersons.entrySet()) {
if(!mUndeterminedGreetingPersons.containsKey(entry.getKey())){
int trackId = entry.getKey();
sendGreeting(entry.getValue());
Greeting greeting = new Greeting();
greeting.trackId = trackId;
greeting.greetingTime = System.currentTimeMillis();
mUndeterminedGreetingPersons.put(entry.getKey(), greeting);
break;
} else{
Greeting greeting = mUndeterminedGreetingPersons.get(entry.getKey());
if(System.currentTimeMillis() - greeting.greetingTime < 2500){
sendGreeting(entry.getValue());
mUndeterminedGreetingPersons.put(entry.getKey(), greeting);
return;
}
}
}
}

public static void clearGreeting(){
Iterator<Map.Entry<String, Greeting>> iterator = mGreetingPersons.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Greeting> entry = iterator.next();
if(!mPersons.containsKey(entry.getKey())){
iterator.remove();
}
}

Iterator<Map.Entry<Integer, Greeting>> iterator2 = mUndeterminedGreetingPersons.entrySet().iterator();
while (iterator2.hasNext()) {
Map.Entry<Integer, Greeting> entry = iterator2.next();
if(!mUndeterminedPersons.containsKey(entry.getKey())){
iterator2.remove();
}
}
}

public static void sendGreeting(PersonInfo message) {
try {
JSONObject obj = new JSONObject();
obj.put("type", "greeting");
JSONObject person = new JSONObject();
person.put("id", message.id);
person.put("name", message.name);
person.put("tag", message.tag);
person.put("gender", message.gender);
person.put("trackId", message.trackId);
person.put("score", message.score);
person.put("faceWidth", message.faceWidth);
person.put("isInPicture", isContainSelectPerson);
Skill skill = SkillDbHelper.getInstance().getByType(message.tag);
if(skill != null){
person.put("skillStatus", skill.status);
person.put("resp", skill.resp);
person.put("motionName", skill.motionName);
}
person.put("isSpeakFinish", DuiMessageObserver.mSpeakFinishStatus);
person.put("speakFinishTime", DuiMessageObserver.mSpeakFinishTime);
List<Model> modelList = ModelDbHelper.getInstance().getAll();
if(modelList != null && modelList.size() > 0){
Model model = modelList.get(0);
if(model.workdayHour != null){
person.put("onDutyHourStart", model.workdayHour.onDutyHourStart);
person.put("onDutyHourEnd", model.workdayHour.onDutyHourEnd);
person.put("offDutyHourStart", model.workdayHour.offDutyHourStart);
person.put("offDutyHourEnd", model.workdayHour.offDutyHourEnd);
person.put("dutyWord", "打卡成功");
}
if(model.workTime != null){
person.put("workdayHourStart", model.workTime.workdayHourStart);
person.put("workdayHourEnd", model.workTime.workdayHourEnd);
person.put("weekendHourStart", model.workTime.weekendHourStart);
person.put("weekendHourEnd", model.workTime.weekendHourEnd);
}
}
obj.put("data", person.toString());

// Date date = new Date(System.currentTimeMillis());
// SimpleDateFormat spTime = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");//yyyy-MM-dd/HH:mm:ss HH24 hh12
// String sT = spTime.format(date);
// Logger.e(sT + ":发送消息到H5: " + sendingMsg + "/");
Logger.e("djTtsTime-给H5发消息打招呼:" + System.currentTimeMillis());
String sendingMsg = obj.toString();
MessageUtils.sendMessage(sendingMsg);
} catch (JSONException e) {
e.printStackTrace();
@@ -627,7 +746,7 @@ public class FaceChatMode {
String base64 = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);

HashMap<String, String> postParam = new HashMap<>();
postParam.put("devId", Build.SERIAL);
postParam.put("devId", StatusUtils.getSerialNumber());
postParam.put("timestamp", System.currentTimeMillis() + "");
postParam.put("userId", userId);
postParam.put("type", type);
@@ -728,7 +847,7 @@ public class FaceChatMode {
return;
}
HashMap<String, Object> postParam = new HashMap<>();
postParam.put("devId", Build.SERIAL);
postParam.put("devId", StatusUtils.getSerialNumber());
postParam.put("timestamp", System.currentTimeMillis() + "");
postParam.put("sign", "123456");
postParam.put("records", array);
@@ -762,6 +881,7 @@ public class FaceChatMode {
}
}


@Override
public void onFail(String error) {
Log.e(TAG, "sendStrangerToServer onFail: " + error);
@@ -770,6 +890,9 @@ public class FaceChatMode {
}

public static Stranger saveStranger(PersonInfo personInfo) {
if(personInfo.dfeatures == null || personInfo.dfeatures.length != 256){
return null;
}
long id = System.currentTimeMillis();
Utils.userNewFaces.put(id + "_1", personInfo.dfeatures);
Stranger stranger = new Stranger();
@@ -781,59 +904,113 @@ public class FaceChatMode {
return stranger;
}

private static int introduceTimes = 0;

public static void delayPerform(String dmInput){
if(introduceTimes < 10){
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
introduceNewPartner(dmInput);
introduceTimes++;
}
}, 10000);
} else{
MessageUtils.sendAsrText("您好,多次拍照不合格,请重新介绍");
MessageUtils.sendTtsText("您好,多次拍照不合格,请重新介绍");
}
}

public static void introduce(String dmInput){
introduceTimes = 0;
introduceNewPartner(dmInput);
}

public static void introduceNewPartner(String dmInput){
MessageUtils.sendMessage("识别人数量:" + mPersons.size() + " 未识别人数量:" + mUndeterminedPersons.size());
// if(mUndeterminedPersons.size() == 0){
// MessageUtils.sendAsrText("没有识别到介绍对象");
// MessageUtils.sendTtsText("没有识别到介绍对象");
// return;
// }
Stream<PersonInfo> pInfos = mUndeterminedPersons.values().stream().filter(item-> item.result.hd_fa > 0 && item.result.fa_quality > 0.6f);
if(pInfos.findAny().isPresent()){
MessageUtils.sendAsrText("陌生人人脸质量合格");
pInfos = mUndeterminedPersons.values().stream().filter(item-> item.result.hd_fa > 0 && item.result.fa_quality > 0.6f);
PersonInfo info = pInfos.findFirst().get();
// if(mPersons.size() > 1){
if(mSelectPerson != null){
if(mSelectPerson.id.equals("-1") || mSelectPerson.id.equals("-2")){
MessageUtils.sendAsrText("你没有权限");
MessageUtils.sendTtsText("你没有权限");
}
String name = "";
String type = "";
if(dmInput.contains("贵宾")){
name = "贵宾";
type = "9";
if(!mSelectPerson.tag.equals("4") && !mSelectPerson.tag.equals("5")){
MessageUtils.sendAsrText("你没有权限");
MessageUtils.sendTtsText("你没有权限");
return;
}
} else if(dmInput.contains("同事")){
name = "同事";
type = "5";
if(!mSelectPerson.tag.equals("4") && !mSelectPerson.tag.equals("5")){
MessageUtils.sendAsrText("你没有权限");
MessageUtils.sendTtsText("你没有权限");
return;
}
} else if(dmInput.contains("访客")){
name = "访客";
type = "6";
} else if(dmInput.contains("高管")){
name = "高管";
if(!mSelectPerson.tag.equals("4") && !mSelectPerson.tag.equals("5")){
MessageUtils.sendAsrText("你没有权限");
MessageUtils.sendTtsText("你没有权限");
return;
}
} else if(dmInput.contains("高层")){
name = "高层";
type = "4";
} else{
MessageUtils.sendAsrText("介绍" + name);
if(!mSelectPerson.tag.equals("4")){
MessageUtils.sendAsrText("你没有权限");
MessageUtils.sendTtsText("你没有权限");
return;
}
}
if(!TextUtils.isEmpty(name)){
MessageUtils.sendAsrText("开始创建" + name);
MessageUtils.sendAsrText("开始介绍" + name);
byte[] bitmapBytes = BmpCompressUtils.getBytesByBitmap(Utils.CompressBmp(info.bitmap, info.result), 100, Bitmap.CompressFormat.JPEG);
String base64 = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
base64 = base64.replace("\n", "").replace("\\", "") + "";
newVisitor(mSelectPerson.name, name, type, info.gender, base64);
newVisitor(dmInput, mSelectPerson.name, name, type, info.gender, base64);
} else{
MessageUtils.sendAsrText("开始介绍" + name);
delayPerform(dmInput);
}
} else{
MessageUtils.sendAsrText("当前操作人不是熟人");
MessageUtils.sendAsrText("熟人才能介绍哦");
MessageUtils.sendTtsText("熟人才能介绍哦");
delayPerform(dmInput);
}
// } else{
// MessageUtils.sendAsrText("没有熟人");
// }
} else{
MessageUtils.sendAsrText("陌生人脸部质量不合格");
MessageUtils.sendAsrText("您好,请调整姿势并正视我的双眼");
MessageUtils.sendTtsText("您好,请调整姿势并正视我的双眼");
delayPerform(dmInput);
}
}

public static void newVisitor(String acquaintance, String name, String type, int gender, String base64){
public static void newVisitor(String dmInput, String acquaintance, String name, String type, int gender, String base64){
HashMap<String, Object> postParam = new HashMap<>();
postParam.put("staffName", name);
postParam.put("staffType", type);
postParam.put("gender", gender);
postParam.put("devId", Build.SERIAL);
postParam.put("devId", StatusUtils.getSerialNumber());
postParam.put("staffBase64Img", base64);
MessageUtils.sendAsrText("调用接口");
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(postParam).toString());
HttpUtil.post(Config.DEV_BASE_URL + "system/staff/api/new-staff", requestBody, null, new HttpUtil.HttpCallback<String>() {
HttpUtil.post(Config.CURRENT_URL + "system/staff/api/new-staff", requestBody, null, new HttpUtil.HttpCallback<String>() {
@Override
public void onSuccess(String success) {
try {
@@ -849,15 +1026,19 @@ public class FaceChatMode {
}
String message = "";
if (status == 0) {
message = acquaintance + "介绍" + name + "成功";
message = "介绍成功";
introduceTimes = 10;
} else {
message = acquaintance + "介绍" + name + "失败:" + errMsg;
message = "介绍失败:" + errMsg;
onFail(errMsg);
delayPerform(dmInput);
}
Logger.e(message);
MessageUtils.sendAsrText(message);
MessageUtils.sendTtsText(message);
} catch (Exception e) {
MessageUtils.sendAsrText(e.getMessage());
MessageUtils.sendTtsText(e.getMessage());
delayPerform(dmInput);
e.printStackTrace();
onFail(e.getMessage());
}
@@ -866,7 +1047,59 @@ public class FaceChatMode {
@Override
public void onFail(String error) {
Log.e(TAG, "sendStrangerToServer onFail: " + error);
MessageUtils.sendAsrText(error);
MessageUtils.sendTtsText(error);
delayPerform(dmInput);
}
});
}

public static void uploadPic(Bitmap bitmap) {
byte[] bitmapBytes = BmpCompressUtils.getBytesByBitmap(Utils.CompressBmp(bitmap), 100, Bitmap.CompressFormat.JPEG);
String base64 = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);

HashMap<String, String> postParam = new HashMap<>();
postParam.put("devId", StatusUtils.getSerialNumber());
postParam.put("timestamp", System.currentTimeMillis() + "");
postParam.put("userId", "88888");
postParam.put("type", "7");
postParam.put("faceScore", "0.9");
postParam.put("imgbase64", base64.replace("\n", "").replace("\\", "") + "");
postParam.put("sign", "123456");

RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(postParam).toString());
HttpUtil.post(Config.CURRENT_URL + "system/pass/api/upload-pass", requestBody, null, new HttpUtil.HttpCallback<String>() {
@Override
public void onSuccess(String success) {
try {
JSONTokener t = new JSONTokener(success);
JSONObject obj = (JSONObject) t.nextValue();
int status = -1001001;
String errMsg = "";

if (obj.has("status")) {
status = obj.getInt("status");
}
if (obj.has("errMsg")) {
errMsg = obj.getString("errMsg");
}

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String time = dateFormat.format(new Date(System.currentTimeMillis()));
if (status == 0) {
Logger.e(time + "2分钟上传1次图片成功");
} else {
Logger.e(time + "2分钟上传1次图片成功:" + errMsg);
onFail(errMsg);
}
} catch (Exception e) {
e.printStackTrace();
onFail(e.getMessage());
}
}

@Override
public void onFail(String error) {
Log.e(TAG, "uploadPic onFail: " + error);
}
});
}


+ 7
- 6
app/src/main/java/com/aispeech/nativedemo/face/FaceManager.java View File

@@ -64,7 +64,7 @@ public class FaceManager {
private LefaceEngine mEngine;
private LefaceEngine.InitializationResult mInitResult;
private long nextLogTime = 0;
private long mInterval = 0;
public static long mInterval = 0;
private int mTrackId = -1;
private UpdateCallback mCallback;

@@ -99,9 +99,10 @@ public class FaceManager {
MessageUtils.sendFaceSDKInitStatus(1);
//readFolderList();
} else if(mInitResult == LefaceEngine.InitializationResult.UNAUTHORIZED_DEVICE){
String[] commons = new String[1];
commons[0] = "reboot";
CommandExecution.execCommand(commons, true);
Log.e("test Face","face sdk init fail");
// String[] commons = new String[1];
// commons[0] = "reboot";
// CommandExecution.execCommand(commons, true);
}
}
} catch (IOException e) {
@@ -729,7 +730,7 @@ public class FaceManager {
// String base64 = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
//
// HashMap<String, String> postParam = new HashMap<>();
// postParam.put("devId", Build.SERIAL);
// postParam.put("devId", StatusUtils.getSerialNumber());
// postParam.put("timestamp", System.currentTimeMillis() + "");
// postParam.put("userId", userId);
// postParam.put("type", type);
@@ -830,7 +831,7 @@ public class FaceManager {
// return;
// }
// HashMap<String, Object> postParam = new HashMap<>();
// postParam.put("devId", Build.SERIAL);
// postParam.put("devId", StatusUtils.getSerialNumber());
// postParam.put("timestamp", System.currentTimeMillis() + "");
// postParam.put("sign", "123456");
// postParam.put("records", array);


+ 79
- 22
app/src/main/java/com/aispeech/nativedemo/face/FaceReceptionMode.java View File

@@ -3,16 +3,25 @@ package com.aispeech.nativedemo.face;
import android.graphics.Bitmap;
import android.text.TextUtils;

import com.aispeech.nativedemo.asr.observer.DuiMessageObserver;
import com.aispeech.nativedemo.db.EmpDbHelper;
import com.aispeech.nativedemo.db.ModelDbHelper;
import com.aispeech.nativedemo.db.ReceptionDbHelper;
import com.aispeech.nativedemo.db.SkillDbHelper;
import com.aispeech.nativedemo.entity.Emp;
import com.aispeech.nativedemo.entity.Model;
import com.aispeech.nativedemo.entity.PersonInfo;
import com.aispeech.nativedemo.entity.Reception;
import com.aispeech.nativedemo.entity.Skill;
import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.network.ws.MessageUtils;
import com.aispeech.nativedemo.utils.Utils;
import com.lenovo.lefacesdk.IdentificationResult;
import com.lenovo.lefacesdk.MultiAtt;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@@ -21,12 +30,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

public class FaceReceptionMode {
private static final String TAG = "FaceReceptionMode";
private static final long COLLECT_TIME = 2000l;
private final static long ROUND_TIMES = 3;
private final static long SESSION_TIME = 5 * 60 * 1000;
private static final long COLLECT_TIME = 1000l;
private final static long ROUND_TIMES = 2;
private final static long SESSION_TIME = 1 * 60 * 1000;
private static int mCollectTimes = 0;
private static Map<String, PersonInfo> mGreetPersons = new HashMap<>();
private static Map<String, PersonInfo> mUngreetPersons = new HashMap<>();
@@ -34,6 +44,7 @@ public class FaceReceptionMode {
public static long mInterval = 0;
public static Reception mReception = null;
public static boolean isStrangerAsk = false;
public static boolean isSayWelcome = false;
public static long mFreeTime = 0;

public static List<MultiAtt> detectMultiAtt(Bitmap textureBitmap) {
@@ -57,6 +68,7 @@ public class FaceReceptionMode {
mReception = null;
mFreeTime = 0;
isStrangerAsk = false;
isSayWelcome = false;
mInterval = 0;
MessageUtils.endReceptionMode();
}
@@ -125,7 +137,7 @@ public class FaceReceptionMode {
mUndeterminedPersons.forEach((key, person) -> {
builder.append("陌生人").append(",");
});
MessageUtils.receptionModeStep("第3轮收集数据,开始打招呼:" + builder.toString());
MessageUtils.receptionModeStep("第" + ROUND_TIMES + "轮收集数据,开始打招呼:" + builder.toString());
mCollectTimes = 0;
return true;
} else{
@@ -143,22 +155,39 @@ public class FaceReceptionMode {
}
return;
}
if(mGreetPersons.size() > 0){
Stream<PersonInfo> pInfos = mGreetPersons.values().stream();
PersonInfo info = pInfos.findFirst().get();
sendOperator(info);
} else if(mUngreetPersons.size() > 0){
Stream<PersonInfo> pInfos = mUngreetPersons.values().stream();
PersonInfo info = pInfos.findFirst().get();
sendOperator(info);
}
if(IdentityMode.MODE_CURRENT != IdentityMode.MODE_RECEPTION){
MessageUtils.receptionModeStep("当前不是接待模式");
return;
}
Reception reception = mReception;
if(reception == null){
// if(mReception == null){
// mReception = new Reception();
// mReception.underpinWord = "各位领导你们好,欢迎光临";
// mReception.date = "8-24";
// }
List<Reception> receptionList = ReceptionDbHelper.getInstance().getAll();
if(receptionList.size() > 0){
mReception = receptionList.get(0);
} else{
MessageUtils.receptionModeStep("接待任务为空");
return;
}
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat time = new SimpleDateFormat("MM-dd");
String dateStr = time.format(date);
if(!dateStr.equals(reception.date)){
MessageUtils.receptionModeStep("不在接待时间范围内" + reception.toString());
return;
}

// Date date = new Date(System.currentTimeMillis());
// SimpleDateFormat time = new SimpleDateFormat("MM-dd");
// String dateStr = time.format(date);
// if(!dateStr.equals(mReception.date)){
// MessageUtils.receptionModeStep("不在接待时间范围内" + mReception.toString());
// return;
// }
StringBuilder word = new StringBuilder();
AtomicInteger index1 = new AtomicInteger(0);
mUngreetPersons.forEach((key, person) -> {
@@ -181,39 +210,52 @@ public class FaceReceptionMode {
word.append(person.name).append(",");
}
});
length = word.length();
if(length > 0){
word.deleteCharAt(word.lastIndexOf(","));
}
if(index2.get() > 0){
word.append(index2.get() > 1 ? "你们好," : "你好,");
}
AtomicInteger index3 = new AtomicInteger(0);
mUngreetPersons.forEach((key, person) -> {
String id = person.id;
if(reception.guide.size() > 0 && reception.first.contains(id)){
if(mReception.first.contains(id)){
index3.getAndIncrement();
word.append(person.name).append(",");
}
});
mUngreetPersons.forEach((key, person) -> {
String id = person.id;
if(reception.guide.size() > 0 && reception.second.contains(id)){
if(mReception.second.contains(id)){
index3.getAndIncrement();
word.append(person.name).append(",");
}
});
mUngreetPersons.forEach((key, person) -> {
String id = person.id;
if(reception.guide.size() > 0 && reception.third.contains(id)){
if(mReception.third.contains(id)){
index3.getAndIncrement();
word.append(person.name).append(",");
}
});
if(word.length() > 0 && word.length() - length > 0){
if(word.length() > 0 && word.length() - length > 0 && index3.get() > 0){
word.deleteCharAt(word.lastIndexOf(","));
}
if(index3.get() > 0){
word.append(index3.get() > 1 ? "你们好" : "你好");
}
if(!TextUtils.isEmpty(word.toString()) && !isSayWelcome){
word.append(mReception.underpinWord);
isSayWelcome = true;
}
if(TextUtils.isEmpty(word.toString())){
if(mUndeterminedPersons.size() > 2 && !isStrangerAsk){
MessageUtils.receptionModeStep("播放托底话术");
word.append(reception.underpinWord);
isStrangerAsk = true;
if(mUndeterminedPersons.size() > 1 && !isStrangerAsk){
if(mGreetPersons.size() == 0){
MessageUtils.receptionModeStep("播放托底话术");
word.append(mReception.underpinWord);
isStrangerAsk = true;
}
}
}
if(!TextUtils.isEmpty(word.toString())){
@@ -295,7 +337,6 @@ public class FaceReceptionMode {
message.name = "";
message.tag = "6";
message.trackId = att.track_id;
message.startTime = System.currentTimeMillis();
message.result = att;
message.faceWidth = att.fa_w;
message.bitmap = textureBitmap;
@@ -402,4 +443,20 @@ public class FaceReceptionMode {
iterator.remove();
}
}

public static void sendOperator(PersonInfo message) {
try {
JSONObject obj = new JSONObject();
obj.put("type", "receptionOperator");
JSONObject person = new JSONObject();
person.put("id", message.id);
person.put("name", message.name);
person.put("tag", message.tag);
person.put("trackId", message.trackId);
obj.put("data", person.toString());
MessageUtils.sendMessage(obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
}

+ 10
- 5
app/src/main/java/com/aispeech/nativedemo/mqtt/MqttConfig.java View File

@@ -2,10 +2,14 @@ package com.aispeech.nativedemo.mqtt;

import android.os.Build;

import com.aispeech.nativedemo.Util;
import com.aispeech.nativedemo.utils.StatusUtils;
import com.aispeech.nativedemo.utils.Utils;

public class MqttConfig {
public static final String HOST_PROD = "tcp://123.57.75.177:1883";
public static final String HOST_CURRENT = HOST_PROD;
public static final String CLIENT_ID = Build.SERIAL;
public static final String CLIENT_ID = StatusUtils.getSerialNumber();
public static final int QUALITY_OF_SERVICE = 1; //0;//服务质量,0最多一次,1最少一次,2只一次
public static final int HAND_MESSAGE = 0;
public static final int HAND_RECONNECT = 1;
@@ -13,8 +17,9 @@ public class MqttConfig {
public static final String USER_NAME = "admin";
public static final String PASSWORD = "public";
public static final String ENV_PROD = "/prod";
public static final String ENV_TEST = "/test";
public static final String ENV_DEV = "/dev";
public static final String ENV_CURRENT = ENV_PROD;
public static final String ENV_CURRENT = ENV_TEST;

/**
* 心跳
@@ -24,7 +29,7 @@ public class MqttConfig {
/**
* 拉取日志
*/
public static final String TOPIC_LOG_UPLOAD = ENV_CURRENT + "/digital_man/" + Build.SERIAL + "/log_upload";
public static final String TOPIC_LOG_UPLOAD = ENV_CURRENT + "/digital_man/" + CLIENT_ID + "/log_upload";

/**
* 日志上传通知
@@ -34,12 +39,12 @@ public class MqttConfig {
/**
* 更新apk
*/
public static final String TOPIC_APK_UPDATE = ENV_CURRENT + "/digital_man/" + Build.SERIAL + "/notify/apk_update";
public static final String TOPIC_APK_UPDATE = ENV_CURRENT + "/digital_man/" + CLIENT_ID + "/notify/apk_update";

/**
* 软件重启(0 : 设备重启;1:软件重启)
*/
public static final String TOPIC_RESTART = ENV_CURRENT + "/digital_man/" + Build.SERIAL + "/notify/restart";
public static final String TOPIC_RESTART = ENV_CURRENT + "/digital_man/" + CLIENT_ID + "/notify/restart";

/**
* 版本更新回复


+ 5
- 5
app/src/main/java/com/aispeech/nativedemo/mqtt/MqttManager.java View File

@@ -161,8 +161,8 @@ public class MqttManager {
private void heartBeatSend() {
JSONObject hb = new JSONObject();
try {
hb.put("id", Build.SERIAL);
hb.put("devId", Build.SERIAL);
hb.put("id", StatusUtils.getSerialNumber());
hb.put("devId", StatusUtils.getSerialNumber());
hb.put("timestamp", System.currentTimeMillis());
hb.put("cpuinfo_max_freq", StatusUtils.getTotalCPUUsage()[0]);
hb.put("cpuinfo_min_freq", StatusUtils.getCpuMinFreq());
@@ -198,7 +198,7 @@ public class MqttManager {
public void sendErrorEventActive(String fileName, String filePath, int uploadType, int level, String type){
try {
JSONObject hb = new JSONObject();
hb.put("devId", Build.SERIAL);
hb.put("devId", StatusUtils.getSerialNumber());
hb.put("file_name", fileName);
hb.put("path", filePath);
hb.put("timestamp", System.currentTimeMillis());
@@ -224,7 +224,7 @@ public class MqttManager {
String topic = message.getData().getString("topic");
if(topic.equals(MqttConfig.TOPIC_LOG_UPLOAD)){
String devId = obj.optString("devId");
if(devId.equals(Build.SERIAL)){
if(devId.equals(StatusUtils.getSerialNumber())){
getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_ACTIVE, Config.ErrorEvent.ERROR_LEVEL_2, "fetch", "mqtt");
}
} else if(topic.equals(MqttConfig.TOPIC_APK_UPDATE)){
@@ -304,7 +304,7 @@ public class MqttManager {
public void getFileUploadPath(int uploadType, int level, String type, String name) {
Logger.e("name = " + name);
HashMap<String, String> map = new HashMap<>();
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("logType", uploadType + "");
map.put("timestamp", System.currentTimeMillis() + "");
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());


+ 4
- 2
app/src/main/java/com/aispeech/nativedemo/mqtt/MqttReply.java View File

@@ -2,6 +2,8 @@ package com.aispeech.nativedemo.mqtt;

import android.os.Build;

import com.aispeech.nativedemo.utils.StatusUtils;

import org.json.JSONException;
import org.json.JSONObject;

@@ -10,7 +12,7 @@ public class MqttReply {
public static String createSetupReplyMessage(int type){
try {
JSONObject setup = new JSONObject();
setup.put("devId", Build.SERIAL);
setup.put("devId", StatusUtils.getSerialNumber());
setup.put("type", type);
setup.put("timestamp", System.currentTimeMillis());
return setup.toString();
@@ -22,7 +24,7 @@ public class MqttReply {
public static String createDownloadApkProgressMessage(int progress){
try {
JSONObject setup = new JSONObject();
setup.put("devId", Build.SERIAL);
setup.put("devId", StatusUtils.getSerialNumber());
setup.put("type", MqttConfig.Upgrade.DOWNLOADING);
setup.put("schedule", progress);
setup.put("timestamp", System.currentTimeMillis());


+ 3
- 1
app/src/main/java/com/aispeech/nativedemo/network/ws/DigiWebSocketServer.java View File

@@ -23,6 +23,7 @@ import com.aispeech.nativedemo.network.DigiNetworkManager;
import com.aispeech.nativedemo.utils.ByteUtil;
import com.aispeech.nativedemo.config.Config;
import com.aispeech.nativedemo.utils.HttpUtil;
import com.aispeech.nativedemo.utils.StatusUtils;
import com.aispeech.nativedemo.utils.Utils;

import org.java_websocket.WebSocket;
@@ -68,6 +69,7 @@ public class DigiWebSocketServer extends WebSocketServer {
MessageUtils.sendWakeupStatus(DuiMessageObserver.mIsSleep);
MessageUtils.sendFaceSDKInitStatus(FaceManager.getInstance().getInitResult());
MessageUtils.sendSpeechSDKInitStatus(DDSService.initCompleted);
MessageUtils.sendVersion();
MessageUtils.getReceptionMode();
}

@@ -207,7 +209,7 @@ public class DigiWebSocketServer extends WebSocketServer {

private void getActivateStatus() {
HashMap<String, String> map = new HashMap<>();
HttpUtil.get(Config.CURRENT_URL + "message/api/get_activate/" + Build.SERIAL, map, new HttpUtil.HttpCallback<String>() {
HttpUtil.get(Config.CURRENT_URL + "message/api/get_activate/" + StatusUtils.getSerialNumber(), map, new HttpUtil.HttpCallback<String>() {

@Override
public void onSuccess(String success) {


+ 54
- 11
app/src/main/java/com/aispeech/nativedemo/network/ws/MessageUtils.java View File

@@ -17,6 +17,8 @@ import com.aispeech.nativedemo.face.FaceChatMode;
import com.aispeech.nativedemo.face.IdentityMode;
import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.shape.ShapeManager;
import com.aispeech.nativedemo.utils.StatusUtils;
import com.aispeech.nativedemo.utils.Utils;

import org.json.JSONException;
import org.json.JSONObject;
@@ -78,7 +80,7 @@ public class MessageUtils {
try {
JSONObject jo = new JSONObject();
jo.put("type", "setSNCode");
jo.put("data", android.os.Build.SERIAL);
jo.put("data", StatusUtils.getSerialNumber());
sendMessage(jo.toString());
} catch (JSONException e) {
e.printStackTrace();
@@ -100,7 +102,7 @@ public class MessageUtils {
try {
JSONObject jo = new JSONObject();
jo.put("type", "initialize");
jo.put("data", android.os.Build.SERIAL);
jo.put("data", StatusUtils.getSerialNumber());
sendMessage(jo.toString());
} catch (JSONException e) {
e.printStackTrace();
@@ -138,7 +140,7 @@ public class MessageUtils {
}
}

public static String sendSkill(String display, String dmInput){
public static String sendSkill(String sessionId, String display, String dmInput){
String readText = "";
try {
JSONObject jo = new JSONObject();
@@ -173,20 +175,22 @@ public class MessageUtils {
}
if(skillObj.has("skillCode")){
int skillCode = skillObj.optInt("skillCode");
if(skillCode == 24){
if(IdentityMode.MODE_CURRENT.equals(IdentityMode.MODE_CHAT)){
FaceChatMode.introduceNewPartner(dmInput);
}
return "";
} else{
// if(skillCode == 24){
// if(IdentityMode.MODE_CURRENT.equals(IdentityMode.MODE_CHAT)){
// FaceChatMode.introduce(dmInput);
// }
// return "";
// } else{
Skill skill = SkillDbHelper.getInstance().getBySkillCode(skillCode);
if(skill != null){
skillObj.put("resp", skill.resp);
skillObj.put("status", skill.status);
skillObj.put("motionName", skill.motionName);
}
}
// }
}
skillObj.put("sessionId", sessionId);
skillObj.put("dmInput", dmInput);
jo.put("data", skillObj.toString());
sendMessage(jo.toString());
} catch (JSONException e){
@@ -197,6 +201,24 @@ public class MessageUtils {
return readText;
}

public static void sendNlpResult(String sessionId, String display, String dmInput){
if(TextUtils.isEmpty(dmInput)){
return;
}
try {
JSONObject jo = new JSONObject();
jo.put("type", "nlpResult");
JSONObject data = new JSONObject();
data.put("sessionId", sessionId);
data.put("display", display);
data.put("dmInput", dmInput);
jo.put("data", data.toString());
sendMessage(jo.toString());
} catch (JSONException e){
e.printStackTrace();
}
}

public static void sendAsr(String data){
try {
JSONObject jo = new JSONObject(data);
@@ -262,7 +284,6 @@ public class MessageUtils {
public static void sendRest(){
List<Model> modelList = ModelDbHelper.getInstance().getAll();
if(modelList != null && modelList.size() > 0){
Log.e("ConfigManager", "modelList size = " + modelList.size());
Model model = modelList.get(0);
try {
JSONObject jo = new JSONObject();
@@ -351,4 +372,26 @@ public class MessageUtils {
throw new RuntimeException(e);
}
}

public static void sendVersion(){
try {
JSONObject jo = new JSONObject();
jo.put("type", "androidVersion");
jo.put("data", Utils.getVersion());
sendMessage(jo.toString());
} catch (JSONException e) {
throw new RuntimeException(e);
}
}

public static void sendConfig(String message){
try {
JSONObject jo = new JSONObject();
jo.put("type", "config");
jo.put("data", message);
sendMessage(jo.toString());
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}

+ 11
- 9
app/src/main/java/com/aispeech/nativedemo/shape/ShapeManager.java View File

@@ -198,12 +198,12 @@ public class ShapeManager {
});
}

public void nlpFromNewDevGpt(String prompt) {
// HashMap<String, Object> map = new HashMap<>();
// map.put("query", prompt);
// RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());
Logger.e("prompt = " + prompt);
HttpUtil.get("http://192.168.10.100:5001/chat_meetingroom_order?query=" + prompt, new HashMap<>(), new HttpUtil.HttpCallback<String>() {
public void nlpFromNewDevGpt(String content) {
HashMap<String, Object> map = new HashMap<>();
map.put("content", content);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());
Logger.e("content = " + content);
HttpUtil.post("http://192.168.10.104:8081/data", requestBody, null, new HttpUtil.HttpCallback<String>() {

@Override
public void onSuccess(String success) {
@@ -211,7 +211,9 @@ public class ShapeManager {
try {
JSONTokener t = new JSONTokener(success);
JSONObject obj = (JSONObject) t.nextValue();
if (obj.has("data")) {
String msg = obj.optString("msg");
DDSManager.getInstance().speakText(msg);
// if (obj.has("code")) {
// String response = obj.optString("msg");
// if(JSONUtils.isJson(response)) {
// String readText = MessageUtils.sendSkill(response);
@@ -221,8 +223,8 @@ public class ShapeManager {
// } else{
// DDSManager.getInstance().speakText(response);
// }
MessageUtils.sendMaxModel(success);
}
// MessageUtils.sendMaxModel(success);
// }
} catch (Exception e) {
e.printStackTrace();
onFail(e.getMessage());


+ 4
- 3
app/src/main/java/com/aispeech/nativedemo/upload/UploadManager.java View File

@@ -10,6 +10,7 @@ import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.mqtt.MqttManager;
import com.aispeech.nativedemo.mqtt.MqttConfig;
import com.aispeech.nativedemo.utils.HttpUtil;
import com.aispeech.nativedemo.utils.StatusUtils;

import org.json.JSONException;
import org.json.JSONObject;
@@ -84,7 +85,7 @@ public class UploadManager {
public void getFileUploadPath(int uploadType, int level, String type, String name) {
Logger.e("name = " + name);
HashMap<String, String> map = new HashMap<>();
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("logType", uploadType + "");
map.put("timestamp", System.currentTimeMillis() + "");
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());
@@ -159,7 +160,7 @@ public class UploadManager {
return;
}
HashMap<String, String> map = new HashMap<>();
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("logType", uploadType + "");
map.put("timestamp", System.currentTimeMillis() + "");
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());
@@ -223,7 +224,7 @@ public class UploadManager {
if(logs != null && logs.length > 0){
for(File log : logs){
HashMap<String, String> map = new HashMap<>();
map.put("devId", Build.SERIAL);
map.put("devId", StatusUtils.getSerialNumber());
map.put("logType", uploadType + "");
map.put("timestamp", System.currentTimeMillis() + "");
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());


+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/utils/ConfigClass.java View File

@@ -134,7 +134,7 @@ public class ConfigClass {
DeviceInfo.DEV_ID = SharedPreferencesUtil.getStringValue(context, "DeviceInfo.DEV_ID", "");
Log.d(TAG, "initDeviceInfo: DeviceInfo.DEV_ID->" + DeviceInfo.DEV_ID);
//DeviceInfo.DEV_SN
DeviceInfo.DEV_SN = SharedPreferencesUtil.getStringValue(context, "DeviceInfo.DEV_SN", android.os.Build.SERIAL);
DeviceInfo.DEV_SN = SharedPreferencesUtil.getStringValue(context, "DeviceInfo.DEV_SN", StatusUtils.getSerialNumber());
Log.d(TAG, "initDeviceInfo: DeviceInfo.DEV_SN->" + DeviceInfo.DEV_SN);
//DeviceInfo.GATE_ID
DeviceInfo.GATE_ID = SharedPreferencesUtil.getStringValue(context, "DeviceInfo.GATE_ID", "");


+ 37
- 0
app/src/main/java/com/aispeech/nativedemo/utils/StatusUtils.java View File

@@ -9,8 +9,12 @@ import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.aispeech.nativedemo.DuiApplication;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -20,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.lang.reflect.Method;

public class StatusUtils {

@@ -334,4 +339,36 @@ public class StatusUtils {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getRssi();
}

public static String getDeviceId() {
return Settings.Secure.getString(DuiApplication.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}

public static String getSerialNumber() {
String serialNumber;

try {
Class< ? > c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);

serialNumber = (String) get.invoke(c,"gsm.sn1");
if (serialNumber.equals(""))
serialNumber = (String) get.invoke(c,"ril.serialnumber");
if (serialNumber.equals(""))
serialNumber = (String) get.invoke(c,"ro.serialno");
if (serialNumber.equals(""))
serialNumber = (String) get.invoke(c,"sys.serialnumber");
if (serialNumber.equals(""))
serialNumber = Build.SERIAL;

// If none of the methods above worked
if (serialNumber.equals(""))
serialNumber = null;
} catch (Exception e) {
e.printStackTrace();
serialNumber = null;
}

return serialNumber;
}
}

+ 108
- 0
app/src/main/java/com/aispeech/nativedemo/utils/Utils.java View File

@@ -4,7 +4,10 @@ import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -19,6 +22,8 @@ import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

import com.aispeech.nativedemo.DuiApplication;
import com.aispeech.nativedemo.entity.ProcessEntity;
import com.lenovo.lefacesdk.MultiAtt;
import com.lenovo.lefacesdk.RectEx;

@@ -38,6 +43,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

@@ -343,6 +349,21 @@ public class Utils {
return bmp1;
}

public static Bitmap CompressBmp(Bitmap bmp) {//获取到图片
Rect rect0 = new Rect();
rect0.set(0, 0, bmp.getWidth(), bmp.getHeight());

int left = 0;
int top = 0;
int right = bmp.getWidth();
int bottom = bmp.getHeight();
Rect rect1 = new Rect();
rect1.set(left, top, right, bottom);
rect0.union(rect1);
Bitmap bmp1 = BmpCompressUtils.ImageCropWithRect(bmp, rect0);
return bmp1;
}

public static void setApplication(Application application) {
myApplication = application;
}
@@ -501,4 +522,91 @@ public class Utils {
Log.e("TAG", "wifiState: " + wifiType);
return wifiType;
}

public static String getVersion(){
String versionName = "";
try {
PackageInfo packageInfo = DuiApplication.getContext().getPackageManager().getPackageInfo(DuiApplication.getContext().getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionName;
}

public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {
Matrix m = new Matrix();
m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
try {
Bitmap bmp1 = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
return bmp1;
} catch (OutOfMemoryError ex) {
ex.printStackTrace();
}
return null;
}

public static boolean isProcessAlive(String packageName) {
String[] commons = new String[1];
commons[0] = "ps";
CommandExecution.CommandResult result = CommandExecution.execCommand(commons, true);
return result.successMsg.contains(packageName);

// HashMap<String, String> processMap = new HashMap<>();
// String[] commons = new String[1];
// commons[0] = "ps";
// CommandExecution.CommandResult result = CommandExecution.execCommand(commons, true);
// try {
// ArrayList<String> psMsg = new ArrayList<>();
// for (String s : result.successMsg.split("\n")) {
// if (!s.equals("")) {
// psMsg.add(s);
// }
// }
// // Log.e(TAG, "总个数: " + psMsg.size());
// ArrayList<ProcessEntity> entities = new ArrayList<>();
// for (int i = 0; i < psMsg.size(); i++) {
// String[] s = psMsg.get(i).split(" ");
// ArrayList<String> list = new ArrayList<>();
// for (int i1 = 0; i1 < s.length; i1++) {
// if (!s[i1].equals("")) {
// list.add(s[i1]);
// }
// }
// ProcessEntity processEntity = new ProcessEntity();
// try {
// processEntity.setUSER(list.get(0));
// processEntity.setPID(list.get(1));
// processEntity.setPPID(list.get(2));
// processEntity.setVSZ(list.get(3));
// processEntity.setRSS(list.get(4));
// processEntity.setWCHAN(list.get(5));
// processEntity.setADDR(list.get(6));
// processEntity.setS(list.get(7));
// processEntity.setNAME(list.get(8));
// } catch (IndexOutOfBoundsException e) {
// processEntity.setUSER(list.get(0));
// processEntity.setPID(list.get(1));
// processEntity.setNAME(list.get(list.size() - 1));
// }
// //Log.e(TAG, "num : " + list.size() + "/" + psMsg.get(i));
// entities.add(processEntity);
// }
// for (int i = 0; i < entities.size(); i++) {
// processMap.put(entities.get(i).getNAME(), entities.get(i).getPID());
// }
// return processMap;
// } catch (IndexOutOfBoundsException e) {
// e.printStackTrace();
// Log.e(TAG, "getProcessInfo: " + result.successMsg + "\n ----------------------------- " + result.errorMsg);
// return processMap;
// }
}

public static void startWatchdogActivity() {
String[] commons = new String[1];
commons[0] = "am start -n com.lecooai.lewatchdog/.MainActivity";
CommandExecution.CommandResult commandResult = CommandExecution.execCommand(commons, true);
// logCommandResult(commandResult);
}
}

+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/widget/AlertWindowView.java View File

@@ -488,7 +488,7 @@ public class AlertWindowView extends ConstraintLayout implements FaceManager.Upd
boolean isContinue = FaceChatMode.featExtract(results, textureBitmap);
if(isContinue){
DDSManager.getInstance().wakeUpDDSDialog();
FaceChatMode.confirmCurrentPerson(textureBitmap);
FaceChatMode.confirmCurrentPerson();
}
// if(!mFaceManager.hasPerson()){
// DDSManager.getInstance().stopDDSDialog();


+ 13
- 3
app/src/main/res/layout/activity_main.xml View File

@@ -16,18 +16,28 @@
android:rotationY="180"
android:id="@+id/texture_hdmi"
android:layout_width="2000dp"
android:layout_height="1125dp" />
android:layout_height="1125dp"
android:visibility="gone"/>

<WebView
android:id="@+id/webview"
android:layout_width="2160px"
android:layout_height="3840px" />
android:layout_height="3840px"
android:visibility="gone"/>

<WebView
android:id="@+id/webview2"
android:layout_width="2160px"
android:layout_height="3840px"
android:visibility="gone"/>

<com.aispeech.nativedemo.widget.CameraTextureView
android:id="@+id/texture"
android:layout_width="2048px"
android:layout_height="1536px"
app:layout_constraintTop_toBottomOf="@id/webview"/>
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

<ImageView
android:id="@+id/image"


Loading…
Cancel
Save