@@ -27,6 +27,7 @@ import com.aispeech.dui.dds.DDSInitListener; | |||
import com.aispeech.dui.dds.DDSMode; | |||
import com.aispeech.dui.dds.agent.tts.TTSEngine; | |||
import com.aispeech.dui.dds.exceptions.DDSNotInitCompleteException; | |||
import com.aispeech.nativedemo.face.FaceManager; | |||
import com.aispeech.nativedemo.log.Logger; | |||
import com.aispeech.nativedemo.mqtt.MqttManager; | |||
import com.aispeech.nativedemo.network.ws.MessageUtils; | |||
@@ -48,6 +49,8 @@ public class DDSService extends Service { | |||
public static final String TAG = "DDSService"; | |||
private static boolean isStarted = false; | |||
public static int initCompleted = 0; | |||
public DDSService() { | |||
} | |||
@@ -114,11 +117,14 @@ public class DDSService extends Service { | |||
private DDSInitListener mInitListener = new DDSInitListener() { | |||
@Override | |||
public void onInitComplete(boolean isFull) { | |||
Logger.d("思必驰初始化成功:onInitComplete " + isFull); | |||
Logger.e("思必驰初始化成功:onInitComplete " + isFull); | |||
if (isFull) { | |||
// 发送一个init成功的广播 | |||
Logger.e("init face sdk"); | |||
FaceManager.getInstance(DuiApplication.getContext()).initEngine(); | |||
Logger.e("init face sdk over"); | |||
sendBroadcast(new Intent("ddsdemo.intent.action.init_complete")); | |||
MessageUtils.sendSpeechSDKInitStatus(1); | |||
initCompleted = 1; | |||
try { | |||
DDS.getInstance().getAgent().getTTSEngine().setMode(TTSEngine.LOCAL); | |||
// DDS.getInstance().getAgent().getTTSEngine().setMode(DDSMode.TTS_SILENCE); | |||
@@ -27,11 +27,11 @@ public class DuiApplication extends Application { | |||
public void onCreate() { | |||
super.onCreate(); | |||
mContext = this; | |||
Logger.init(); | |||
Fresco.initialize(this); | |||
Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler); | |||
FaceManager.getInstance(this).initEngine(); | |||
// FaceManager.getInstance(this).initEngine(); | |||
DigiNetworkManager.getManager().init(this); | |||
Logger.init(); | |||
copyDbAndConfig(); | |||
} | |||
@@ -62,30 +62,30 @@ public class DuiApplication extends Application { | |||
@Override | |||
public void uncaughtException(Thread t, Throwable e) { | |||
if (e instanceof OutOfMemoryError) { | |||
Log.d(TAG, "uncaughtException(): " + e.toString()); | |||
Logger.e("uncaughtException(): " + e.toString()); | |||
long freeMemory = Runtime.getRuntime().freeMemory(); | |||
long totalMemory = Runtime.getRuntime().totalMemory(); | |||
long maxMemory = Runtime.getRuntime().maxMemory(); | |||
int availableProcessors = Runtime.getRuntime().availableProcessors(); | |||
Log.d(TAG, "freeMemory " + freeMemory); | |||
Log.d(TAG, "totalMemory " + totalMemory); | |||
Log.d(TAG, "maxMemory " + maxMemory); | |||
Log.d(TAG, "availableProcessors " + availableProcessors); | |||
Logger.e( "freeMemory " + freeMemory); | |||
Logger.e( "totalMemory " + totalMemory); | |||
Logger.e( "maxMemory " + maxMemory); | |||
Logger.e( "availableProcessors " + availableProcessors); | |||
Log.d(TAG, "status file:\n" + readSystemFile("/proc/" + android.os.Process.myPid() + "/status")); | |||
Log.d(TAG, "limits file:\n" + readSystemFile("/proc/" + android.os.Process.myPid() + "/limits")); | |||
Log.d(TAG, "threads-max file:\n" + readSystemFile("/proc/sys/kernel/threads-max")); | |||
Logger.e( "status file:\n" + readSystemFile("/proc/" + android.os.Process.myPid() + "/status")); | |||
Logger.e( "limits file:\n" + readSystemFile("/proc/" + android.os.Process.myPid() + "/limits")); | |||
Logger.e( "threads-max file:\n" + readSystemFile("/proc/sys/kernel/threads-max")); | |||
int pid = android.os.Process.myPid(); | |||
Log.d(TAG, "pid: " + pid); | |||
Logger.e( "pid: " + pid); | |||
File fd = new File("/proc/" + pid + "/fd"); | |||
if (fd.exists() && fd.isDirectory()) { | |||
File[] files = fd.listFiles(); | |||
if (files != null && files.length > 0) { | |||
Log.d(TAG, "fd 目录下有 " + files.length + " 个文件"); | |||
Log.d(TAG, String.format("%10S %10S %10S %10S", "name", "isFile", "isDirectory", "length")); | |||
Logger.e( "fd 目录下有 " + files.length + " 个文件"); | |||
Logger.e( String.format("%10S %10S %10S %10S", "name", "isFile", "isDirectory", "length")); | |||
for (File f : files) { | |||
Log.d(TAG, String.format("%10S %10S %10S %10S", | |||
Logger.e( String.format("%10S %10S %10S %10S", | |||
f.getName(), f.isFile() ? f.isFile() : "", f.isDirectory() ? f.isDirectory() : "", f.isFile() ? f.length() : "")); | |||
} | |||
} | |||
@@ -259,12 +259,12 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
public void onClick(View v) { | |||
// mCameraController.closeCamera(); | |||
// mTextureView = null; | |||
// List<Skill> skillList = SkillDbHelper.getInstance().getAll(); | |||
// String str = ""; | |||
// for (Skill skill : skillList) { | |||
// str += skill.toString(); | |||
// } | |||
// mWSManager.sendMsg(str); | |||
List<Skill> skillList = SkillDbHelper.getInstance().getAll(); | |||
String str = ""; | |||
for (Skill skill : skillList) { | |||
str += skill.toString(); | |||
} | |||
mWSManager.sendMsg(str); | |||
// try { | |||
// DDS.getInstance().getAgent().stopDialog(); | |||
// } catch (DDSNotInitCompleteException e) { | |||
@@ -280,11 +280,11 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
// throw new RuntimeException(e); | |||
// } | |||
try { | |||
DDS.getInstance().getAgent().sendText(""); | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
// try { | |||
// DDS.getInstance().getAgent().sendText(""); | |||
// } catch (DDSNotInitCompleteException e) { | |||
// throw new RuntimeException(e); | |||
// } | |||
} | |||
}); | |||
open = findViewById(R.id.open_camera); | |||
@@ -490,8 +490,8 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
mRectFaceView.setBackground(xml2); | |||
mRectFaceView.setRotationY(180); | |||
if(SystemClock.uptimeMillis() - mDoaTime > 1000){ | |||
mDoaTime = SystemClock.uptimeMillis(); | |||
if(System.currentTimeMillis() - mDoaTime > 1000){ | |||
mDoaTime = System.currentTimeMillis(); | |||
int doa = 0; | |||
if(bd_x != 0 && bd_x > 100){ | |||
doa = 90 - (1080 - bd_x) / 25; | |||
@@ -550,7 +550,7 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
// if (Utils.userLogs == null || Utils.userLogs.isEmpty()) { | |||
// Utils.userLogs = DbHelper.Instance().loadAllLogs(); | |||
// } | |||
// backgroundHandler.post(periodicDetect); | |||
backgroundHandler.post(periodicDetect); | |||
} | |||
private final Runnable periodicDetect = new Runnable() { | |||
@@ -7,7 +7,9 @@ import android.util.Log; | |||
import com.aispeech.dui.dds.DDS; | |||
import com.aispeech.dui.dds.agent.DMTaskCallback; | |||
import com.aispeech.dui.dds.agent.MessageObserver; | |||
import com.aispeech.nativedemo.DuiApplication; | |||
import com.aispeech.nativedemo.MainActivity; | |||
import com.aispeech.nativedemo.face.FaceManager; | |||
import com.aispeech.nativedemo.log.Logger; | |||
import com.aispeech.nativedemo.mqtt.MqttManager; | |||
import com.aispeech.nativedemo.network.ws.MessageUtils; | |||
@@ -74,14 +76,14 @@ public class DuiMessageObserver implements MessageObserver { | |||
Log.e(Tag, display); | |||
Log.e(Tag, nlg); | |||
String readText = nlg; | |||
// if(FaceManager.getInstance(DuiApplication.getContext()).hasPerson()){ | |||
if(JSONUtils.isJson(display)){ | |||
if(FaceManager.getInstance(DuiApplication.getContext()).hasPerson()) { | |||
if (JSONUtils.isJson(display)) { | |||
readText = MessageUtils.sendSkill(display); | |||
try { | |||
jsonObject.put("nlg", ""); | |||
jsonObject.put("display", ""); | |||
jsonObject.put("display", ""); | |||
if(!TextUtils.isEmpty(readText)){ | |||
if (!TextUtils.isEmpty(readText)) { | |||
JSONObject jo = new JSONObject(); | |||
jo.put("type", "djTtsNlpText"); | |||
jo.put("data", readText); | |||
@@ -91,11 +93,10 @@ public class DuiMessageObserver implements MessageObserver { | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
else{ | |||
} else { | |||
try { | |||
jsonObject.put("nlg", ""); | |||
jsonObject.put("display", ""); | |||
jsonObject.put("display", ""); | |||
JSONObject jo = new JSONObject(); | |||
jo.put("type", "djTtsNlpText"); | |||
@@ -107,21 +108,14 @@ public class DuiMessageObserver implements MessageObserver { | |||
e.printStackTrace(); | |||
} | |||
} | |||
// else{ | |||
// try { | |||
// jsonObject.put("nlg", ""); | |||
// jsonObject.put("display", ""); | |||
// } catch (JSONException e) { | |||
// throw new RuntimeException(e); | |||
// } | |||
// if(!TextUtils.isEmpty(mAsrWord)){ | |||
// if(MainActivity.selectType == 1){ | |||
// ShapeManager.getInstance().nlpFromChatGpt(mAsrWord); | |||
// } else{ | |||
// ShapeManager.getInstance().nlpFromSixB(mAsrWord); | |||
// } | |||
// } | |||
// } | |||
} else{ | |||
try { | |||
jsonObject.put("nlg", ""); | |||
jsonObject.put("display", ""); | |||
} catch (JSONException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
// } else{ | |||
// try { | |||
// jsonObject.put("nlg", ""); | |||
@@ -153,7 +147,7 @@ public class DuiMessageObserver implements MessageObserver { | |||
DDS.getInstance().getAgent().unSubscribe(this); | |||
} | |||
public static boolean mIsSleep = true; | |||
public static boolean mIsSleep = false; | |||
public static boolean mSpeakFinishStatus = true; | |||
public static long mSpeakFinishTime = 0; | |||
public static String mAsrWord = ""; | |||
@@ -166,9 +160,10 @@ public class DuiMessageObserver implements MessageObserver { | |||
MessageUtils.sendChatMessage(data); | |||
break; | |||
case "context.input.text": | |||
// if(FaceManager.getInstance(DuiApplication.getContext()).hasPerson()){ | |||
//判断有人的时候才发送给大模型 | |||
if(FaceManager.getInstance(DuiApplication.getContext()).hasPerson()){ | |||
MessageUtils.sendAsr(data); | |||
// } | |||
} | |||
break; | |||
case "context.widget.content": | |||
@@ -261,6 +261,8 @@ public class ConfigManager { | |||
skill.skillCode = jsonObject.optString("skillCode"); | |||
skill.info = jsonObject.optString("info"); | |||
skill.resp = jsonObject.optString("resp"); | |||
skill.motionId = jsonObject.optString("motionId"); | |||
skill.motionName = jsonObject.optString("motionName"); | |||
SkillDbHelper.getInstance().add(skill); | |||
} | |||
if (obj.has("timestamp")) { | |||
@@ -18,6 +18,8 @@ public class SkillBuilder implements DatabaseBuilder<Skill>{ | |||
skill.skillCode = (query.getString(query.getColumnIndex("skill_code"))); | |||
skill.info = (query.getString(query.getColumnIndex("info"))); | |||
skill.resp = (query.getString(query.getColumnIndex("resp"))); | |||
skill.motionId = (query.getString(query.getColumnIndex("motionId"))); | |||
skill.motionName = (query.getString(query.getColumnIndex("motionName"))); | |||
return skill; | |||
} | |||
@@ -30,6 +32,8 @@ public class SkillBuilder implements DatabaseBuilder<Skill>{ | |||
contentValues.put("skill_code",skill.skillCode); | |||
contentValues.put("info",skill.info); | |||
contentValues.put("resp",skill.resp); | |||
contentValues.put("motionId",skill.motionId); | |||
contentValues.put("motionName",skill.motionName); | |||
return contentValues; | |||
} | |||
} |
@@ -49,16 +49,14 @@ public class DDSManager { | |||
public void wakeUpDDSDialog(){ | |||
synchronized (lock){ | |||
if (DuiMessageObserver.mIsSleep) { | |||
try { | |||
startTimer(); | |||
DDS.getInstance().getAgent().sendText(""); | |||
DuiMessageObserver.mIsSleep = false; | |||
try { | |||
startTimer(); | |||
DDS.getInstance().getAgent().sendText(""); | |||
DuiMessageObserver.mIsSleep = false; | |||
// WakeupWord minorWord = getWakeupWord("xiao zhi xiao zhi", "小智小智", "0.25", "在呢,我是小智"); | |||
// DDS.getInstance().getAgent().getWakeupEngine().addMainWakeupWord(minorWord); | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
} | |||
@@ -91,15 +89,13 @@ public class DDSManager { | |||
public void stopDDSDialog(){ | |||
synchronized (lock){ | |||
if (!DuiMessageObserver.mIsSleep) { | |||
try { | |||
cancelTimer(); | |||
DDS.getInstance().getAgent().stopDialog(); | |||
try { | |||
cancelTimer(); | |||
DDS.getInstance().getAgent().stopDialog(); | |||
// WakeupWord minorWord = getWakeupWord("xiaasdsadsawqewdadzhiasfaiaozhi", "小智小智!!@!@!#!@!@!$$$", "0.25", "在呢,我是小智"); | |||
// DDS.getInstance().getAgent().getWakeupEngine().addMainWakeupWord(minorWord); | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
} | |||
@@ -34,7 +34,7 @@ public class PersonInfo { | |||
this.trackId = trackId; | |||
this.score = score; | |||
this.result = att; | |||
this.startTime = this.updateTime = SystemClock.uptimeMillis(); | |||
this.startTime = this.updateTime = System.currentTimeMillis(); | |||
this.faceWidth = result.fa_w; | |||
} | |||
@@ -14,6 +14,8 @@ public class Skill implements Serializable { | |||
public String skillCode; | |||
public String info; | |||
public String resp; | |||
public String motionId; | |||
public String motionName; | |||
@NonNull | |||
@Override | |||
@@ -26,6 +28,8 @@ public class Skill implements Serializable { | |||
obj.put("skillCode", skillCode); | |||
obj.put("info", info); | |||
obj.put("resp", resp); | |||
obj.put("motionId", motionId); | |||
obj.put("motionName", motionName); | |||
} catch (JSONException e) { | |||
throw new RuntimeException(e); | |||
} | |||
@@ -63,6 +63,7 @@ public class FaceManager { | |||
private StringBuilder mSb; | |||
private UpdateCallback mCallback; | |||
private int initResult = 0; | |||
private FaceManager(Context context) { | |||
mContext = context; | |||
@@ -85,19 +86,25 @@ public class FaceManager { | |||
mEngine = new LefaceEngine(mContext, ACCESS_KEY, SECRET_KEY); | |||
mInitResult = mEngine.initialize(); | |||
Log.d(TAG, "engine initialization result:" + mInitResult.toString()); | |||
Logger.e("engine initialization result:" + mInitResult.toString()); | |||
if (mInitResult == LefaceEngine.InitializationResult.SUCCESS) { | |||
mEngine.initializeMultiDetector(); | |||
mEngine.initializeRecognizer(); | |||
initResult = 1; | |||
MessageUtils.sendFaceSDKInitStatus(1); | |||
//readFolderList(); | |||
} | |||
} | |||
} catch (IOException e) { | |||
Log.e(TAG, "Failed to initialize an image classifier.", e); | |||
Logger.e("Failed to initialize an image classifier.", e); | |||
MessageUtils.sendFaceSDKInitStatus(0); | |||
} | |||
} | |||
public int getInitResult(){ | |||
return initResult; | |||
} | |||
public void setCallback(UpdateCallback callback){ | |||
mCallback = callback; | |||
} | |||
@@ -114,12 +121,12 @@ public class FaceManager { | |||
int h = textureBitmap.getHeight(), w = textureBitmap.getWidth(); | |||
if(mInterval == 0){ | |||
mInterval = SystemClock.uptimeMillis(); | |||
mInterval = System.currentTimeMillis(); | |||
} | |||
long detectStartTime = SystemClock.uptimeMillis(); | |||
long detectStartTime = System.currentTimeMillis(); | |||
List<MultiAtt> results_att = mEngine.detectMultiAtt(textureBitmap); | |||
long detectEndTime = SystemClock.uptimeMillis(); | |||
long detectEndTime = System.currentTimeMillis(); | |||
Log.d(TAG, "----- detectMultiAtt time ----- " + (detectEndTime - detectStartTime)); | |||
mSb = new StringBuilder(); | |||
// for (MultiAtt att : results_att) { | |||
@@ -144,12 +151,12 @@ public class FaceManager { | |||
for (MultiAtt att : results_att) { | |||
if (att.hd_fa != 0) { | |||
int minus = att.fa_x2 - att.fa_x1; | |||
if(minus < 500 && minus > 140){ //根据view分辨率修改 | |||
if(minus < 500 && minus > 150){ //根据view分辨率修改 | |||
results.add(results.size(), results_att.get(idx)); | |||
} | |||
} else if(att.hd_bd != 0){ | |||
int minus = att.bd_x2 - att.bd_x1; | |||
if(minus < 1500 && minus > 150){ | |||
if(minus < 1500 && minus > 500){ | |||
results.add(results.size(), results_att.get(idx)); | |||
} | |||
} | |||
@@ -197,14 +204,14 @@ public class FaceManager { | |||
filterUndeterminedFace(results); | |||
} | |||
public boolean featExtract(List<MultiAtt> results, Bitmap textureBitmap) { | |||
long featStartTime = SystemClock.uptimeMillis(); | |||
long featStartTime = System.currentTimeMillis(); | |||
//TODO 过滤 | |||
// filterExactLyFace(results); | |||
// filterUndeterminedFace(results); | |||
List<float[]> employeeList = mEngine.featExtract(textureBitmap, results); | |||
long featEndTime = SystemClock.uptimeMillis(); | |||
long featEndTime = System.currentTimeMillis(); | |||
Log.d(TAG, "----- featExtract time ----- " + (featEndTime - featStartTime)); | |||
isContainSelectPerson = false; | |||
@@ -214,13 +221,14 @@ public class FaceManager { | |||
} | |||
PersonInfo person = identifyFace(employeeList.get(j), textureBitmap, results.get(j)); | |||
if(person != null){ | |||
Logger.e("识别对象为:" + person.name); | |||
if(mSelectPerson != null && person.id.equals(mSelectPerson.id)){ | |||
isContainSelectPerson = true; | |||
} | |||
if(person.id.equals("-2")){ //添加识别条件 人脸质量高和识别置信度底 | |||
if(mUndeterminedPersons.containsKey(person.trackId)){ | |||
PersonInfo origin = mUndeterminedPersons.get(person.trackId); | |||
origin.updateTime = SystemClock.uptimeMillis(); | |||
origin.updateTime = System.currentTimeMillis(); | |||
origin.result = person.result; | |||
origin.faceWidth = person.faceWidth; | |||
mUndeterminedPersons.put(person.trackId, origin); | |||
@@ -231,7 +239,7 @@ public class FaceManager { | |||
//已经认出人的处理 | |||
if(mPersons.containsKey(person.id)){ | |||
PersonInfo origin = mPersons.get(person.id); | |||
origin.updateTime = SystemClock.uptimeMillis(); | |||
origin.updateTime = System.currentTimeMillis(); | |||
origin.result = person.result; | |||
origin.faceWidth = person.faceWidth; | |||
mPersons.put(person.id, origin); | |||
@@ -246,10 +254,10 @@ public class FaceManager { | |||
} | |||
} | |||
} | |||
if(SystemClock.uptimeMillis() - mInterval < 1000){ | |||
if(System.currentTimeMillis() - mInterval < 1000){ | |||
return false; | |||
} | |||
mInterval = SystemClock.uptimeMillis(); | |||
mInterval = System.currentTimeMillis(); | |||
return true; | |||
} | |||
@@ -275,7 +283,7 @@ public class FaceManager { | |||
// filterHighLevelAndMaxFaceId(); //选出预选人 未确定face大 已确定身份高face大 | |||
selectCandidate(mSelectPerson.faceWidth); | |||
Stream<PersonInfo> pInfos = mCandidates.stream().filter(item->SystemClock.uptimeMillis() - item.candidateTime >= CANDIDATE_STAY_TIME); | |||
Stream<PersonInfo> pInfos = mCandidates.stream().filter(item->System.currentTimeMillis() - item.candidateTime >= CANDIDATE_STAY_TIME); | |||
Map<String,PersonInfo> candidatesKnown = new HashMap<>(); | |||
Map<Integer,PersonInfo> candidatesUnknown = new HashMap<>(); | |||
@@ -316,7 +324,7 @@ public class FaceManager { | |||
private void selectCandidate(int faceSize){ | |||
//TODO 过期处理 | |||
List<PersonInfo> candidates = new ArrayList<>(); | |||
long time = SystemClock.uptimeMillis(); | |||
long time = System.currentTimeMillis(); | |||
mPersons.forEach((key, value) -> { | |||
if(value.faceWidth - faceSize > FACE_DIFF){ | |||
Optional<PersonInfo> pInfo = mCandidates.stream().filter(item->item.id.equals(key)).findFirst(); | |||
@@ -389,7 +397,7 @@ public class FaceManager { | |||
String key = entry.getKey(); | |||
PersonInfo value = entry.getValue(); | |||
if (att.track_id == value.trackId) { | |||
value.updateTime = SystemClock.uptimeMillis(); | |||
value.updateTime = System.currentTimeMillis(); | |||
value.faceWidth = att.fa_w; | |||
value.result = att; | |||
mPersons.put(key, value); | |||
@@ -431,7 +439,7 @@ public class FaceManager { | |||
if(mUndeterminedPersons.containsKey(att.track_id)){ | |||
PersonInfo stranger = mUndeterminedPersons.get(att.track_id); | |||
if(stranger.id.equals("-2")){ | |||
stranger.updateTime = SystemClock.uptimeMillis(); | |||
stranger.updateTime = System.currentTimeMillis(); | |||
stranger.faceWidth = att.fa_w; | |||
stranger.result = att; | |||
mUndeterminedPersons.put(att.track_id, stranger); | |||
@@ -446,13 +454,13 @@ public class FaceManager { | |||
message.name = ""; | |||
message.tag = "6"; | |||
message.trackId = att.track_id; | |||
message.startTime = SystemClock.uptimeMillis(); | |||
message.startTime = System.currentTimeMillis(); | |||
message.result = att; | |||
message.faceWidth = att.fa_w; | |||
mUndeterminedPersons.put(att.track_id, message); | |||
} else{ | |||
PersonInfo message = mUndeterminedPersons.get(att.track_id); | |||
message.updateTime = SystemClock.uptimeMillis(); | |||
message.updateTime = System.currentTimeMillis(); | |||
message.faceWidth = att.fa_w; | |||
message.result = att; | |||
mUndeterminedPersons.put(att.track_id, message); | |||
@@ -462,7 +470,7 @@ public class FaceManager { | |||
} | |||
} | |||
private static final int PERSON_EXPIRE_TIME = 5000; | |||
private static final int PERSON_EXPIRE_TIME = 2000; //人物过期时间 | |||
private static final int UNKNOWN_PERSON_EXPIRE_TIME = 1500; | |||
private static final int FACE_DIFF = 70; | |||
private static final int CANDIDATE_STAY_TIME = 3000; | |||
@@ -479,7 +487,7 @@ public class FaceManager { | |||
while (iterator.hasNext()) { | |||
Map.Entry<String, PersonInfo> entry = iterator.next(); | |||
PersonInfo person = entry.getValue(); | |||
if(SystemClock.uptimeMillis() - person.updateTime > PERSON_EXPIRE_TIME) { | |||
if(System.currentTimeMillis() - person.updateTime > PERSON_EXPIRE_TIME) { | |||
iterator.remove(); | |||
//置空当前选择人 | |||
if(mSelectPerson != null && person.id.equals(mSelectPerson.id)){ | |||
@@ -495,7 +503,7 @@ public class FaceManager { | |||
while (iterator.hasNext()) { | |||
Map.Entry<Integer, PersonInfo> entry = iterator.next(); | |||
PersonInfo person = entry.getValue(); | |||
if(SystemClock.uptimeMillis() - person.updateTime > UNKNOWN_PERSON_EXPIRE_TIME) { | |||
if(System.currentTimeMillis() - person.updateTime > UNKNOWN_PERSON_EXPIRE_TIME) { | |||
iterator.remove(); | |||
//置空当前选择人 | |||
if(mSelectPerson != null && person.id.equals(mSelectPerson.id)){ | |||
@@ -651,6 +659,7 @@ public class FaceManager { | |||
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); | |||
@@ -751,8 +760,20 @@ public class FaceManager { | |||
} | |||
public boolean hasPerson(){ | |||
if(mPersons.size() > 0 || mUndeterminedPersons.size() > 0){ | |||
MessageUtils.sendMessage("识别人数量:" + mPersons.size() + " 未识别人数量:" + mUndeterminedPersons.size()); | |||
// if(mPersons.size() > 0 || mUndeterminedPersons.size() > 0){ | |||
// return true; | |||
// } | |||
if(mPersons.size() > 0){ | |||
return true; | |||
} else if(mUndeterminedPersons.size() > 0){ | |||
Iterator <Map.Entry< Integer, PersonInfo >> iterator = mUndeterminedPersons.entrySet().iterator(); | |||
while (iterator.hasNext()) { | |||
Map.Entry< Integer, PersonInfo > entry = iterator.next(); | |||
if(entry.getValue().result.fa_quality > 0.6f){ | |||
return true; | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
@@ -2,14 +2,19 @@ package com.aispeech.nativedemo.network.ws; | |||
import android.content.Context; | |||
import android.os.Build; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.SystemClock; | |||
import android.util.Log; | |||
import com.aispeech.nativedemo.DDSService; | |||
import com.aispeech.nativedemo.MainActivity; | |||
import com.aispeech.nativedemo.asr.observer.DuiMessageObserver; | |||
import com.aispeech.nativedemo.config.ConfigManager; | |||
import com.aispeech.nativedemo.db.InitializeDbHelper; | |||
import com.aispeech.nativedemo.dds.DDSManager; | |||
import com.aispeech.nativedemo.entity.Initialize; | |||
import com.aispeech.nativedemo.face.FaceManager; | |||
import com.aispeech.nativedemo.log.Logger; | |||
import com.aispeech.nativedemo.mqtt.MqttManager; | |||
import com.aispeech.nativedemo.network.DigiNetworkManager; | |||
@@ -58,6 +63,9 @@ public class DigiWebSocketServer extends WebSocketServer { | |||
String ad1 = address1.getHostAddress(); | |||
// String ad2 = address1.getHostName(); | |||
getActivateStatus(ad1); | |||
MessageUtils.sendWakeupStatus(DuiMessageObserver.mIsSleep); | |||
MessageUtils.sendFaceSDKInitStatus(FaceManager.getInstance(context).getInitResult()); | |||
MessageUtils.sendSpeechSDKInitStatus(DDSService.initCompleted); | |||
} | |||
@Override | |||
@@ -131,7 +139,14 @@ public class DigiWebSocketServer extends WebSocketServer { | |||
if (Objects.equals(ex.getMessage(), "Address already in use")) { | |||
/*MyDbHelper.Instance().dbClose(); | |||
android.os.Process.killProcess(android.os.Process.myPid());*/ | |||
WebSocketManager.getInstance(context).createWebSocketServer(); | |||
Looper.prepare(); | |||
new Handler().postDelayed(new Runnable() { | |||
@Override | |||
public void run() { | |||
WebSocketManager.getInstance(context).createWebSocketServer(); | |||
} | |||
}, 3000); | |||
Looper.loop(); | |||
} | |||
// removeConnection(conn); | |||
// MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "socket_status", "onError"); | |||
@@ -12,6 +12,7 @@ import com.aispeech.nativedemo.db.ModelDbHelper; | |||
import com.aispeech.nativedemo.db.SkillDbHelper; | |||
import com.aispeech.nativedemo.entity.Model; | |||
import com.aispeech.nativedemo.entity.Skill; | |||
import com.aispeech.nativedemo.log.Logger; | |||
import com.aispeech.nativedemo.shape.ShapeManager; | |||
import org.json.JSONException; | |||
@@ -153,6 +154,7 @@ public class MessageUtils { | |||
if(skill != null){ | |||
skillObj.put("resp", skill.resp); | |||
skillObj.put("status", skill.status); | |||
skillObj.put("motionName", skill.motionName); | |||
} | |||
} | |||
jo.put("data", skillObj.toString()); | |||
@@ -175,6 +177,7 @@ public class MessageUtils { | |||
person.put("type", "asr"); | |||
person.put("data", txt); | |||
sendMessage(person.toString()); | |||
// ShapeManager.getInstance().nlpFromNewDevGpt(txt); | |||
} | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
@@ -91,6 +91,8 @@ public class WebSocketManager { | |||
public void sendMsg(String message) { | |||
Logger.e("发送消息给H5" + message); | |||
wsServer.broadcast(message); | |||
if(wsServer != null){ | |||
wsServer.broadcast(message); | |||
} | |||
} | |||
} |
@@ -2,6 +2,7 @@ package com.aispeech.nativedemo.shape; | |||
import android.os.AsyncTask; | |||
import android.os.Build; | |||
import android.text.TextUtils; | |||
import android.util.Log; | |||
import com.aispeech.nativedemo.DuiApplication; | |||
@@ -9,9 +10,11 @@ import com.aispeech.nativedemo.asr.observer.DuiMessageObserver; | |||
import com.aispeech.nativedemo.db.SkillDbHelper; | |||
import com.aispeech.nativedemo.dds.DDSManager; | |||
import com.aispeech.nativedemo.entity.Skill; | |||
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.widget.pageview.utils.JSONUtils; | |||
import org.apache.xmlrpc.XmlRpcException; | |||
import org.apache.xmlrpc.XmlRpcRequest; | |||
@@ -193,4 +196,43 @@ 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.110:5001/chat_qa?query=" + prompt, new HashMap<>(), new HttpUtil.HttpCallback<String>() { | |||
@Override | |||
public void onSuccess(String success) { | |||
Logger.e("nlpFromNewDevGpt success = " + success); | |||
try { | |||
JSONTokener t = new JSONTokener(success); | |||
JSONObject obj = (JSONObject) t.nextValue(); | |||
if (obj.has("msg")) { | |||
String response = obj.optString("msg"); | |||
if(JSONUtils.isJson(response)) { | |||
String readText = MessageUtils.sendSkill(response); | |||
if(!TextUtils.isEmpty(readText)){ | |||
DDSManager.getInstance().speakText(response); | |||
} | |||
} else{ | |||
DDSManager.getInstance().speakText(response); | |||
} | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
onFail(e.getMessage()); | |||
DDSManager.getInstance().speakText(e.getMessage()); | |||
} | |||
} | |||
@Override | |||
public void onFail(String error) { | |||
Log.e(TAG, "nlpFromNewDevGpt error = " + error); | |||
DDSManager.getInstance().speakText(error); | |||
} | |||
}); | |||
} | |||
} |
@@ -23,6 +23,7 @@ import com.aispeech.dui.dds.exceptions.DDSNotInitCompleteException; | |||
import com.aispeech.nativedemo.DDSService; | |||
import com.aispeech.nativedemo.MainActivity; | |||
import com.aispeech.nativedemo.R; | |||
import com.aispeech.nativedemo.log.Logger; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -145,7 +146,7 @@ public class LauncherActivity extends Activity { | |||
} | |||
break; | |||
} else { | |||
Log.w(TAG, "waiting init complete finish..."); | |||
Logger.e("waiting init complete finish..."); | |||
} | |||
try { | |||
Thread.sleep(800); | |||