@@ -29,6 +29,7 @@ import com.aispeech.dui.dds.agent.tts.TTSEngine; | |||
import com.aispeech.dui.dds.exceptions.DDSNotInitCompleteException; | |||
import com.aispeech.nativedemo.log.Logger; | |||
import com.aispeech.nativedemo.mqtt.MqttManager; | |||
import com.aispeech.nativedemo.network.ws.MessageUtils; | |||
import com.aispeech.nativedemo.network.ws.WebSocketManager; | |||
import com.aispeech.nativedemo.ui.LauncherActivity; | |||
import com.aispeech.nativedemo.config.Config; | |||
@@ -117,25 +118,22 @@ public class DDSService extends Service { | |||
if (isFull) { | |||
// 发送一个init成功的广播 | |||
sendBroadcast(new Intent("ddsdemo.intent.action.init_complete")); | |||
MessageUtils.sendSpeechSDKInitStatus(1); | |||
try { | |||
DDS.getInstance().getAgent().getTTSEngine().setMode(TTSEngine.LOCAL); | |||
// DDS.getInstance().getAgent().getTTSEngine().setMode(DDSMode.TTS_SILENCE); | |||
// DDS.getInstance().getAgent().getTTSEngine().setSpeaker("zhilingfp"); | |||
DDS.getInstance().getAgent().getTTSEngine().setSpeaker("hqqiaf","hqqiaf_lstm_210909.bin"); | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
Logger.e("思必驰--------"); | |||
} else{ | |||
Logger.e("思必驰++++++++++++++++++++"); | |||
} | |||
DDS.getInstance().setAudioDebug(true); | |||
try { | |||
DDS.getInstance().getAgent().getTTSEngine().setMode(TTSEngine.LOCAL); | |||
// DDS.getInstance().getAgent().getTTSEngine().setMode(DDSMode.TTS_SILENCE); | |||
// DDS.getInstance().getAgent().getTTSEngine().setSpeaker("zhilingfp"); | |||
DDS.getInstance().getAgent().getTTSEngine().setSpeaker("hqqiaf","hqqiaf_lstm_210909.bin"); | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
// startTtsListening(); | |||
AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); | |||
// audioManager.setParameters("audio_devices_out_active=AUDIO_CODEC"); | |||
// or | |||
audioManager.setParameters("audio_devices_out_active=AUDIO_DEVICE_OUT_AUX_DIGITAL"); | |||
// or | |||
// audioManager.setParameters("audio_devices_out_active=AUDIO_HDMI,AUDIO_CODEC"); | |||
// startTtsListening(); | |||
} | |||
@Override | |||
@@ -198,20 +198,20 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
@Override | |||
public void onClick(View v) { | |||
// mWSManager.destroyWebSocketServer(); | |||
// List<Emp> empList = EmpDbHelper.getInstance().getAll(); | |||
// String feature = ""; | |||
// for (Emp emp : empList) { | |||
// feature += emp.toString() + "\n"; | |||
// } | |||
// mWSManager.sendMsg(feature); | |||
JSONObject jo = new JSONObject(); | |||
try { | |||
jo.put("type", "djTtsText"); | |||
jo.put("data", "今天天气真好"); | |||
WebSocketManager.getInstance(MainActivity.this).sendMsg(jo.toString()); | |||
} catch (JSONException e) { | |||
throw new RuntimeException(e); | |||
List<Emp> empList = EmpDbHelper.getInstance().getAll(); | |||
String feature = ""; | |||
for (Emp emp : empList) { | |||
feature += emp.toString() + "\n"; | |||
} | |||
mWSManager.sendMsg(feature); | |||
// JSONObject jo = new JSONObject(); | |||
// try { | |||
// jo.put("type", "djTtsText"); | |||
// jo.put("data", "今天天气真好"); | |||
// WebSocketManager.getInstance(MainActivity.this).sendMsg(jo.toString()); | |||
// } catch (JSONException e) { | |||
// throw new RuntimeException(e); | |||
// } | |||
} | |||
}); | |||
startWeb = findViewById(R.id.start_web_socket); | |||
@@ -395,7 +395,7 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式 | |||
webSettings.setDomStorageEnabled(true); | |||
mWebView.loadUrl("http://192.168.10.244:48088"); | |||
// mWebView.loadUrl("http://192.168.10.244:48088"); | |||
} | |||
private WebSocketManager mWSManager; | |||
@@ -524,7 +524,9 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
private void killApp() { | |||
mWSManager.destroyWebSocketServer(); | |||
// stopService(DDSService.newDDSServiceIntent(this, "start")); | |||
android.os.Process.killProcess(android.os.Process.myPid()); | |||
System.exit(0); | |||
} | |||
private void rebootDev() { | |||
@@ -566,9 +568,9 @@ public class MainActivity extends Activity implements DuiUpdateObserver.UpdateCa | |||
boolean isContinue = mFaceManager.featExtract(results, textureBitmap); | |||
if(isContinue){ | |||
if(isInitComplete){ | |||
DDSManager.getInstance().wakeUpDDSDialog(); | |||
} | |||
// if(isInitComplete){ | |||
// DDSManager.getInstance().wakeUpDDSDialog(); | |||
// } | |||
mFaceManager.confirmCurrentPerson(textureBitmap); | |||
} | |||
// if(!mFaceManager.hasPerson()){ | |||
@@ -216,7 +216,7 @@ public class DuiMessageObserver implements MessageObserver { | |||
String errId = errorObj.optString("errId"); | |||
if(!errId.equals("071304") && !errId.equals("071305") && !errId.equals("071310") && !errId.equals("071317") && !errId.equals("071318")){ | |||
Logger.e("对话错误: " + data); | |||
MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "speech_sdk_err_code", Tag); | |||
// MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "speech_sdk_err_code", Tag); | |||
} | |||
} catch (JSONException e) { | |||
throw new RuntimeException(e); | |||
@@ -21,6 +21,8 @@ import org.json.JSONObject; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Timer; | |||
import java.util.TimerTask; | |||
public class DDSManager { | |||
private static final String TAG = "DDSManager"; | |||
@@ -43,10 +45,13 @@ public class DDSManager { | |||
return mInstance; | |||
} | |||
private Timer mTimer; | |||
public void wakeUpDDSDialog(){ | |||
synchronized (lock){ | |||
if (DuiMessageObserver.mIsSleep) { | |||
try { | |||
startTimer(); | |||
DDS.getInstance().getAgent().sendText(""); | |||
DuiMessageObserver.mIsSleep = false; | |||
// WakeupWord minorWord = getWakeupWord("xiao zhi xiao zhi", "小智小智", "0.25", "在呢,我是小智"); | |||
@@ -58,10 +63,37 @@ public class DDSManager { | |||
} | |||
} | |||
private void startTimer(){ | |||
if(mTimer == null){ | |||
mTimer = new Timer(); | |||
} | |||
mTimer.schedule(new TimerTask() { | |||
@Override | |||
public void run() { | |||
if(DuiMessageObserver.mIsSleep){ | |||
try { | |||
DDS.getInstance().getAgent().sendText(""); | |||
DuiMessageObserver.mIsSleep = false; | |||
} catch (DDSNotInitCompleteException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
} | |||
}, 0, 2000); | |||
} | |||
private void cancelTimer(){ | |||
if(mTimer != null){ | |||
mTimer.cancel(); | |||
mTimer = null; | |||
} | |||
} | |||
public void stopDDSDialog(){ | |||
synchronized (lock){ | |||
if (!DuiMessageObserver.mIsSleep) { | |||
try { | |||
cancelTimer(); | |||
DDS.getInstance().getAgent().stopDialog(); | |||
// WakeupWord minorWord = getWakeupWord("xiaasdsadsawqewdadzhiasfaiaozhi", "小智小智!!@!@!#!@!@!$$$", "0.25", "在呢,我是小智"); | |||
// DDS.getInstance().getAgent().getWakeupEngine().addMainWakeupWord(minorWord); | |||
@@ -79,14 +111,14 @@ public class DDSManager { | |||
// DDS.getInstance().getAgent().stopDialog(); | |||
// } | |||
// DDS.getInstance().getAgent().avatarClick(text); | |||
DDS.getInstance().getAgent().sendText(""); | |||
// DDS.getInstance().getAgent().sendText(""); | |||
if(!TextUtils.isEmpty(text)){ | |||
JSONObject jo = new JSONObject(); | |||
jo.put("type", "djTtsText"); | |||
jo.put("data", text); | |||
WebSocketManager.getInstance(MainActivity.instance).sendMsg(jo.toString()); | |||
} | |||
} catch (JSONException | DDSNotInitCompleteException e) { | |||
} catch (JSONException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@@ -139,7 +171,7 @@ public class DDSManager { | |||
}); | |||
try { | |||
WakeupWord minorWord = getWakeupWord("xiao zhi xiao zhi", "小智小智", "0.25", "在呢,我是小智"); | |||
WakeupWord minorWord = getWakeupWord("xiao zhi xiao zhi", "小智小智呀呀呀", "0.25", "在呢,我是小智"); | |||
DDS.getInstance().getAgent().getWakeupEngine().addMainWakeupWord(minorWord); | |||
List<WakeupWord> words = new ArrayList<>(); | |||
words.add(getWakeupWord("bi zui", "闭嘴", "0.18", "好的")); | |||
@@ -89,6 +89,7 @@ public class FaceManager { | |||
if (mInitResult == LefaceEngine.InitializationResult.SUCCESS) { | |||
mEngine.initializeMultiDetector(); | |||
mEngine.initializeRecognizer(); | |||
MessageUtils.sendFaceSDKInitStatus(1); | |||
//readFolderList(); | |||
} | |||
} | |||
@@ -105,7 +106,7 @@ public class FaceManager { | |||
if(mEngine == null){ | |||
return null; | |||
} | |||
Log.e(TAG, "-----------------detectMultiAtt----------------"); | |||
// Log.e(TAG, "-----------------detectMultiAtt----------------"); | |||
if (textureBitmap == null) { | |||
Log.e(TAG, "-----------------textureBitmap null----------------"); | |||
return null; | |||
@@ -28,7 +28,9 @@ import java.net.InetAddress; | |||
import java.net.InetSocketAddress; | |||
import java.nio.ByteBuffer; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Objects; | |||
import java.util.Timer; | |||
import java.util.TimerTask; | |||
@@ -37,16 +39,19 @@ public class DigiWebSocketServer extends WebSocketServer { | |||
private static final String TAG = "DigiWebSocketServer"; | |||
public Long heartbeatTime = 0l; | |||
public Context context; | |||
public List<WebSocket> mConns; | |||
public DigiWebSocketServer(InetSocketAddress host, Context context) { | |||
super(host); | |||
this.context = context; | |||
mConns = new ArrayList<>(); | |||
} | |||
@Override | |||
public void onOpen(WebSocket conn, ClientHandshake handshake) { | |||
Log.e("websocket", "onOpen()一个客户端连接成功:" + conn.getRemoteSocketAddress()); | |||
Utils.websocketList.add(conn.getRemoteSocketAddress().toString()); | |||
mConns.add(conn); | |||
InetSocketAddress address = conn.getRemoteSocketAddress(); | |||
InetAddress address1 = address.getAddress(); | |||
String ad1 = address1.getHostAddress(); | |||
@@ -58,7 +63,9 @@ public class DigiWebSocketServer extends WebSocketServer { | |||
public void onClose(WebSocket conn, int code, String reason, boolean remote) { | |||
Logger.e("websocket", conn.getRemoteSocketAddress() + "onClose()服务器关闭"); | |||
Utils.websocketList.remove(conn.getRemoteSocketAddress().toString()); | |||
MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "socket_status", "onClose"); | |||
mConns.add(conn); | |||
removeConnection(conn); | |||
// MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "socket_status", "onClose"); | |||
} | |||
@Override | |||
@@ -92,7 +99,7 @@ public class DigiWebSocketServer extends WebSocketServer { | |||
String requestName = obj.optString("requestName"); | |||
String errMsg = obj.optString("errMsg"); | |||
Logger.e(requestName + ":" + errMsg); | |||
MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "web_request_error", "requestErr"); | |||
// MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "web_request_error", "requestErr"); | |||
} else if(type.equals("asrSwitch")){ | |||
boolean status = obj.optBoolean("status"); | |||
if(status){ | |||
@@ -124,7 +131,8 @@ public class DigiWebSocketServer extends WebSocketServer { | |||
/*MyDbHelper.Instance().dbClose(); | |||
android.os.Process.killProcess(android.os.Process.myPid());*/ | |||
} | |||
MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "socket_status", "onError"); | |||
removeConnection(conn); | |||
// MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "socket_status", "onError"); | |||
ex.printStackTrace(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
@@ -151,6 +159,13 @@ public class DigiWebSocketServer extends WebSocketServer { | |||
} | |||
public void removeAllConn(){ | |||
for(WebSocket conn : mConns){ | |||
removeConnection(conn); | |||
} | |||
mConns.clear(); | |||
} | |||
private void getActivateStatus(String address) { | |||
HashMap<String, String> map = new HashMap<>(); | |||
HttpUtil.get("http://39.107.77.235:8080/message/api/get_activate/" + Build.SERIAL, map, new HttpUtil.HttpCallback<String>() { | |||
@@ -196,4 +196,26 @@ public class MessageUtils { | |||
} | |||
} | |||
} | |||
public static void sendFaceSDKInitStatus(int status){ | |||
try { | |||
JSONObject jo = new JSONObject(); | |||
jo.put("type", "faceSdk"); | |||
jo.put("data", status); | |||
sendMessage(jo.toString()); | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
public static void sendSpeechSDKInitStatus(int status){ | |||
try { | |||
JSONObject jo = new JSONObject(); | |||
jo.put("type", "speechSdk"); | |||
jo.put("data", status); | |||
sendMessage(jo.toString()); | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -63,6 +63,7 @@ public class WebSocketManager { | |||
public void stopWebSocketServer(){ | |||
try { | |||
Log.e(TAG, "stopWebSocketServer"); | |||
wsServer.removeAllConn(); | |||
wsServer.stop(); | |||
} catch (IOException | InterruptedException e) { | |||
e.printStackTrace(); | |||
@@ -16,13 +16,12 @@ | |||
android:rotationY="180" | |||
android:id="@+id/texture_hdmi" | |||
android:layout_width="2000dp" | |||
android:layout_height="1125dp" | |||
android:visibility="gone"/> | |||
android:layout_height="1125dp" /> | |||
<WebView | |||
android:id="@+id/webview" | |||
android:layout_width="2160px" | |||
android:layout_height="3000px" /> | |||
android:layout_height="3840px" /> | |||
<com.aispeech.nativedemo.widget.CameraTextureView | |||
android:id="@+id/texture" | |||