Explorar el Código

优化打招呼逻辑

tags/A.1.0.5.0_20230809_base^2
tangmingjie hace 2 años
padre
commit
d2c87fb900
Se han modificado 8 ficheros con 60 adiciones y 51 borrados
  1. +11
    -8
      app/src/main/java/com/aispeech/nativedemo/MainActivity.java
  2. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/entity/PersonInfo.java
  3. +38
    -32
      app/src/main/java/com/aispeech/nativedemo/face/FaceChatMode.java
  4. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/face/FaceManager.java
  5. +0
    -1
      app/src/main/java/com/aispeech/nativedemo/face/FaceReceptionMode.java
  6. +1
    -0
      app/src/main/java/com/aispeech/nativedemo/mqtt/MqttConfig.java
  7. +7
    -7
      app/src/main/java/com/aispeech/nativedemo/network/ws/MessageUtils.java
  8. +1
    -1
      app/src/main/java/com/aispeech/nativedemo/widget/AlertWindowView.java

+ 11
- 8
app/src/main/java/com/aispeech/nativedemo/MainActivity.java Ver fichero

@@ -228,11 +228,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);
}
}
});
@@ -543,23 +542,27 @@ 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) {


+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/entity/PersonInfo.java Ver fichero

@@ -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){


+ 38
- 32
app/src/main/java/com/aispeech/nativedemo/face/FaceChatMode.java Ver fichero

@@ -82,9 +82,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 +96,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 +113,8 @@ public class FaceChatMode {
}
}
}
if(System.currentTimeMillis() - mInterval < 1000){
return false;
}
Logger.e("djTtsTime-收集数据结束:" + System.currentTimeMillis());
// sendStrangerToServer();
mInterval = System.currentTimeMillis();
return true;
}

@@ -123,7 +124,7 @@ public class FaceChatMode {
filterUndeterminedFace(results, textureBitmap);
}

public static void confirmCurrentPerson(Bitmap textureBitmap){
public static void confirmCurrentPerson(){
if(mPersons.size() == 0 && mUndeterminedPersons.size() == 0){
return;
}
@@ -133,11 +134,11 @@ public class FaceChatMode {
if(mUndeterminedPersons.size() > 0){
//选择未确定脸大的人
mSelectPerson = selectUnknownMaxFacePerson(mUndeterminedPersons);
sendMsgAndLog(textureBitmap);
sendMsgAndLog();
}
return;
} else{
mSelectPerson = selectKnownMaxTagAndFacePerson();
sendMsgAndLog();
}
return;
}
@@ -169,13 +170,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 +260,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 +305,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 +322,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();
@@ -403,7 +408,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 +423,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 +464,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 +549,8 @@ 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();
@@ -833,7 +839,7 @@ public class FaceChatMode {
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 {


+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/face/FaceManager.java Ver fichero

@@ -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;



+ 0
- 1
app/src/main/java/com/aispeech/nativedemo/face/FaceReceptionMode.java Ver fichero

@@ -295,7 +295,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;


+ 1
- 0
app/src/main/java/com/aispeech/nativedemo/mqtt/MqttConfig.java Ver fichero

@@ -13,6 +13,7 @@ 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;



+ 7
- 7
app/src/main/java/com/aispeech/nativedemo/network/ws/MessageUtils.java Ver fichero

@@ -173,19 +173,19 @@ 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.introduceNewPartner(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);
}
}
// }
}
jo.put("data", skillObj.toString());
sendMessage(jo.toString());


+ 1
- 1
app/src/main/java/com/aispeech/nativedemo/widget/AlertWindowView.java Ver fichero

@@ -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();


Cargando…
Cancelar
Guardar