package com.baidu.speech.asr; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.util.Log; import com.baidu.speech.EventListener; import com.baidu.speech.audio.MicrophoneServer; import com.baidu.speech.core.BDSErrorDescription; import com.baidu.speech.core.BDSMessage; import com.baidu.speech.core.BDSParamBase; import com.baidu.speech.core.BDSSDKLoader; import com.baidu.speech.utils.AsrError; import com.baidu.speech.utils.LogUtil; import com.baidu.speech.utils.Policy; import com.kuaishou.weapon.p0.i1; import com.mbridge.msdk.foundation.entity.CampaignEx; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; import java.util.HashMap; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class WakeUpControl implements BDSSDKLoader.BDSCoreEventListener { private static String ASR_PARAM_KEY_OFFLINE_APP_CODE = "offline_param_key_app_code.string"; private static String ASR_PARAM_KEY_PLATFORM = "asr_param_key_platform.string"; private static String ASR_PARAM_KEY_SDK_VERSION = "asr_param_key_sdk_version.string"; private static String COMMON_PARAM_KEY_DEBUG_LOG_LEVEL = "common_param_key_debug_log_level.int"; private static final int EWakeupEngineWorkStatusError = 6; private static final int EWakeupEngineWorkStatusLoaded = 3; private static final int EWakeupEngineWorkStatusNewData = 7; private static final int EWakeupEngineWorkStatusReadyed = 1; private static final int EWakeupEngineWorkStatusStarted = 0; private static final int EWakeupEngineWorkStatusStopped = 2; private static final int EWakeupEngineWorkStatusTriggered = 5; private static final int EWakeupEngineWorkStatusUnLoaded = 4; private static String MIC_PARAM_KEY_AUDIO_FILE_PATH = "mic_audio_file_path.string"; private static String MIC_PARAM_KEY_SOCKET_PORT = "mic_param_key_socket_port.int"; private static String OFFLINE_PARAM_KEY_LICENSE_FILE_PATH = "offline_param_key_license_filepath.string"; private static final String TAG = "WakeUpControl"; private static String WAK_CMD_CONFIG = "wak.config"; private static String WAK_CMD_DATA = "wak.data"; private static String WAK_CMD_LOAD_ENGINE = "wak.load"; private static String WAK_CMD_START = "wak.start"; private static String WAK_CMD_STOP = "wak.stop"; private static String WAK_CMD_UNLOAD_ENGINE = "wak.unload"; private static String WP_PARAM_KEY_ENABLE_MODEL_VAD = "wakeup_param_key_mode.int"; private static String WP_PARAM_KEY_ENABLE_VAD = "wakeup_param_key_enable_vad.bool"; private static String WP_PARAM_KEY_VAD_DAT_FILE_PATH = "wakeup_param_key_vad_dat_file_path.string"; private static String WP_PARAM_KEY_WAKEUP_ACCEPT_AUDIO_DATA = "wakeup_param_key_accept_audio_data.bool"; private static String WP_PARAM_KEY_WAKEUP_DAT_FILE_PATH = "wakeup_param_key_dat_filepath.string"; private static String WP_PARAM_KEY_WAKEUP_KWD = "wakeup_param_key_kwd.bool"; private static String WP_PARAM_KEY_WAKEUP_MODE = "wakeup_param_key_mode.int"; private static String WP_PARAM_KEY_WAKEUP_WORDS = "wakeup_param_key_words.vector<string>"; private static String WP_PARAM_KEY_WAKEUP_WORDS_FILE_PATH = "wakeup_param_key_words_filepath.string"; private Context context; private boolean mFeedBackAudio; private boolean mIsWorking = false; private EventListener mListener; private JSONObject mParams; private BDSSDKLoader.BDSSDKInterface m_Wakeupcore; private String outFile = null; public enum DebugLogLevel { EVRDebugLogLevelOff, EVRDebugLogLevelFatal, EVRDebugLogLevelError, EVRDebugLogLevelWarning, EVRDebugLogLevelInformation, EVRDebugLogLevelDebug, EVRDebugLogLevelTrace } public WakeUpControl(Context context2) { this.context = context2; try { BDSSDKLoader.loadLibraries(); try { BDSSDKLoader.BDSSDKInterface sDKObjectForSDKType = BDSSDKLoader.getSDKObjectForSDKType("WakeupCore", context2); this.m_Wakeupcore = sDKObjectForSDKType; if (sDKObjectForSDKType == null) { throw new Exception("ASR core support is not linked in package"); } else if (sDKObjectForSDKType.instanceInitialized()) { this.m_Wakeupcore.setListener(this); } else { throw new Exception("Failed initialize ASR Core native layer"); } } catch (Throwable th) { th.printStackTrace(); throw new Exception("Can't found ASR Core native method"); } } catch (Throwable unused) { throw new Exception(generateErrorResult(5001)); } } private void asrCallBack(BDSMessage bDSMessage, EventListener eventListener) { int i; int i2; byte[] bArr; String str; String str2; String str3; if (bDSMessage.m_messageName.equals(SpeechConstant.WAKEUP_CALLBACK_NAME)) { int i3 = ((BDSParamBase.BDSIntParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_WAK_STATUS)).iValue; LogUtil.v(TAG, "WPCallBack:" + bDSMessage.toString()); if (i3 != 0) { if (i3 == 1) { str = null; bArr = null; i2 = 0; i = 0; str2 = SpeechConstant.CALLBACK_EVENT_WAKEUP_READY; } else if (i3 == 2) { this.mIsWorking = false; eventListener.onEvent(SpeechConstant.CALLBACK_EVENT_WAKEUP_STOPED, null, null, 0, 0); return; } else if (i3 == 5) { HashMap hashMap = new HashMap(); hashMap.put("word", (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_WAK_RESULT)).iValue); hashMap.put("errorCode", 0); hashMap.put("errorDesc", "wakup success"); eventListener.onEvent(SpeechConstant.CALLBACK_EVENT_WAKEUP_SUCCESS, new JSONObject(hashMap).toString(), null, 0, 0); return; } else if (i3 == 6) { this.mIsWorking = false; int i4 = ((BDSParamBase.BDSIntParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ERROR_DOMAIN)).iValue; String str4 = (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ERROR_DESC)).iValue; try { str3 = generateErrorResult(i4, ((BDSParamBase.BDSIntParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ERROR_CODE)).iValue); } catch (Exception e) { e.printStackTrace(); str3 = ""; } str = str3; bArr = null; i2 = 0; i = 0; str2 = SpeechConstant.CALLBACK_EVENT_WAKEUP_ERROR; } else if (i3 == 7) { byte[] bArr2 = bDSMessage.m_messageData; if (this.mFeedBackAudio && bArr2 != null) { eventListener.onEvent(SpeechConstant.CALLBACK_EVENT_WAKEUP_AUDIO, null, bArr2, 0, bArr2.length); } saveOutFile(bArr2); return; } else { return; } eventListener.onEvent(str2, str, bArr, i2, i); return; } eventListener.onEvent(SpeechConstant.CALLBACK_EVENT_WAKEUP_STARTED, null, null, 0, 0); } } /* JADX WARNING: Removed duplicated region for block: B:23:0x0037 A[SYNTHETIC, Splitter:B:23:0x0037] */ private void clearOutFile() { FileOutputStream fileOutputStream; Throwable th; IOException e; String str = this.outFile; if (str != null && !str.equals("")) { try { fileOutputStream = new FileOutputStream(this.outFile); try { fileOutputStream.write("".getBytes()); } catch (IOException e2) { e = e2; } } catch (IOException e3) { fileOutputStream = null; e = e3; try { e.printStackTrace(); if (fileOutputStream == null) { return; } fileOutputStream.close(); } catch (Throwable th2) { th = th2; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e4) { e4.printStackTrace(); } } throw th; } } catch (Throwable th3) { fileOutputStream = null; th = th3; if (fileOutputStream != null) { } throw th; } try { fileOutputStream.close(); } catch (IOException e5) { e5.printStackTrace(); } } } private String generateErrorResult(int i) { String descFromCode = AsrError.getDescFromCode(i); int i2 = i / 1000; JSONObject jSONObject = new JSONObject(); try { jSONObject.put("error", i2); jSONObject.put(CampaignEx.JSON_KEY_DESC, descFromCode); jSONObject.put("sub_error", i); } catch (JSONException e) { e.printStackTrace(); } return jSONObject.toString(); } private String generateErrorResult(int i, int i2) { if (AsrError.getDescFromCode(i2) == null) { if (i == 38) { if (1 == i2) { i2 = AsrError.ERROR_WAKEUP_ENGINE_EXCEPTION; } else if (2 == i2) { i2 = AsrError.ERROR_WAKEUP_NO_LICENSE; } else if (3 == i2) { i2 = AsrError.ERROR_WAKEUP_INVALID_LICENSE; } else if (4 == i2) { i2 = AsrError.ERROR_WAKEUP_EXCEPTION; } else if (5 == i2) { i2 = AsrError.ERROR_WAKEUP_MODEL_EXCEPTION; } else if (6 == i2) { i2 = AsrError.ERROR_WAKEUP_ENGINE_INITIAL_FAIL; } else if (7 == i2) { i2 = AsrError.ERROR_WAKEUP_MEM_ALLOC_FAIL; } else if (8 == i2) { i2 = AsrError.ERROR_WAKEUP_ENGINE_RESET_FAIL; } else if (9 == i2) { i2 = AsrError.ERROR_WAKEUP_ENGINE_FREE_FAIL; } else if (10 == i2) { i2 = AsrError.ERROR_WAKEUP_ENGINE_NOT_SUPPORT; } else if (11 == i2) { i2 = AsrError.ERROR_WAKEUP_RECOGNIZE_FAIL; } } else if (i == 20 && 1 == i2) { i2 = 3100; } i2 = -1; } return generateErrorResult(i2); } private File getDiskCacheDir(Context context2) { return context2.getCacheDir(); } private BDSErrorDescription initWp(BDSErrorDescription bDSErrorDescription, JSONObject jSONObject) { BDSParamBase bDSParamBase; String str; HashMap<String, BDSParamBase> hashMap; String str2 = null; try { ApplicationInfo applicationInfo = this.context.getPackageManager().getApplicationInfo(this.context.getPackageName(), 128); if (applicationInfo.metaData != null) { str2 = applicationInfo.metaData.getInt("com.baidu.speech.APP_ID") + ""; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String optString = jSONObject.optString("appid", str2); JSONArray optJSONArray = jSONObject.optJSONArray(SpeechConstant.WP_WORDS); Vector vector = new Vector(); if (optJSONArray != null) { for (int i = 0; i < optJSONArray.length(); i++) { try { vector.add(optJSONArray.getString(i)); } catch (JSONException e2) { e2.printStackTrace(); } } } String optString2 = jSONObject.optString(SpeechConstant.WP_DAT_FILEPATH, jSONObject.optString("wp.res-file", jSONObject.optString("res-file", String.format("%s/%s", this.context.getApplicationInfo().nativeLibraryDir, "libbd_easr_s1_merge_normal_20151216.dat.so")))); String optString3 = jSONObject.optString("wp.kws-file", jSONObject.optString(SpeechConstant.WP_WORDS_FILE)); String optString4 = jSONObject.optString(SpeechConstant.IN_FILE); String optString5 = jSONObject.optString("decoder-offline.license-file-path", jSONObject.optString("license-file-path", jSONObject.optString("license"))); int optInt = jSONObject.optInt(SpeechConstant.LOG_LEVEL, -1); if (Log.isLoggable(LogUtil.LOGTAG, 3)) { optInt = 5; } else if (Log.isLoggable(LogUtil.LOGTAG, 2)) { optInt = 6; } this.mFeedBackAudio = jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_DATA, false); this.outFile = jSONObject.optString(SpeechConstant.OUT_FILE); BDSMessage bDSMessage = new BDSMessage(); bDSMessage.m_messageName = WAK_CMD_CONFIG; HashMap<String, BDSParamBase> hashMap2 = new HashMap<>(); bDSMessage.m_messageParams = hashMap2; hashMap2.put(ASR_PARAM_KEY_OFFLINE_APP_CODE, BDSParamBase.objectParam(optString, "java.lang.String")); bDSMessage.m_messageParams.put(WP_PARAM_KEY_WAKEUP_DAT_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString2), "java.lang.String")); bDSMessage.m_messageParams.put(WP_PARAM_KEY_WAKEUP_WORDS, BDSParamBase.objectParam(vector, "java.util.Vector;")); bDSMessage.m_messageParams.put(WP_PARAM_KEY_WAKEUP_WORDS_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString3), "java.lang.String")); bDSMessage.m_messageParams.put(OFFLINE_PARAM_KEY_LICENSE_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString5), "java.lang.String")); bDSMessage.m_messageParams.put(MIC_PARAM_KEY_AUDIO_FILE_PATH, BDSParamBase.objectParam(optString4, "java.lang.String")); if (jSONObject.optBoolean(SpeechConstant.WP_VAD_ENABLE, false)) { bDSMessage.m_messageParams.put(WP_PARAM_KEY_ENABLE_VAD, BDSParamBase.boolParam(true)); bDSMessage.m_messageParams.put(WP_PARAM_KEY_ENABLE_MODEL_VAD, BDSParamBase.intParam(2)); hashMap = bDSMessage.m_messageParams; str = WP_PARAM_KEY_VAD_DAT_FILE_PATH; bDSParamBase = BDSParamBase.objectParam(this.context.getApplicationInfo().nativeLibraryDir, "java.lang.String"); } else { hashMap = bDSMessage.m_messageParams; str = WP_PARAM_KEY_ENABLE_VAD; bDSParamBase = BDSParamBase.boolParam(false); } hashMap.put(str, bDSParamBase); if (jSONObject.optBoolean("wp.kwd_enable", false)) { bDSMessage.m_messageParams.put(WP_PARAM_KEY_WAKEUP_KWD, BDSParamBase.boolParam(true)); } bDSMessage.m_messageParams.put(MIC_PARAM_KEY_SOCKET_PORT, BDSParamBase.intParam(jSONObject.optInt("audio.socketport"))); if (optInt != -1) { bDSMessage.m_messageParams.put(COMMON_PARAM_KEY_DEBUG_LOG_LEVEL, BDSParamBase.intParam(optInt)); } bDSMessage.m_messageParams.put(WP_PARAM_KEY_WAKEUP_ACCEPT_AUDIO_DATA, BDSParamBase.boolParam(this.mFeedBackAudio)); boolean optBoolean = jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_VOLUME, true); if (!optBoolean) { bDSMessage.m_messageParams.put("mic_accept_audio_volume.bool", BDSParamBase.boolParam(optBoolean)); } int optInt2 = jSONObject.optInt("wp.mode", 0); if (optInt2 > 0) { bDSMessage.m_messageParams.put(WP_PARAM_KEY_WAKEUP_MODE, BDSParamBase.intParam(optInt2)); } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PLATFORM, BDSParamBase.objectParam("Android", "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SDK_VERSION, BDSParamBase.objectParam("C++ ASR core", "java.lang.String")); try { int postMessage = this.m_Wakeupcore.postMessage(bDSMessage); if (postMessage == 0) { return bDSErrorDescription; } BDSErrorDescription bDSErrorDescription2 = new BDSErrorDescription(); bDSErrorDescription2.errorCode = -2; bDSErrorDescription2.errorDomain = 1; bDSErrorDescription2.errorDescription = "JNI: readyParamsWpStart Call to Native layer returned error! err( " + postMessage + " )"; return bDSErrorDescription2; } catch (Throwable th) { th.printStackTrace(); BDSErrorDescription bDSErrorDescription3 = new BDSErrorDescription(); bDSErrorDescription3.errorCode = -2; bDSErrorDescription3.errorDomain = 1; bDSErrorDescription3.errorDescription = "JNI: readyParamsWpStart Call to Native layer returned error! err"; return bDSErrorDescription3; } } /* JADX WARNING: Removed duplicated region for block: B:61:0x00f9 A[SYNTHETIC, Splitter:B:61:0x00f9] */ /* JADX WARNING: Removed duplicated region for block: B:66:0x0103 A[SYNTHETIC, Splitter:B:66:0x0103] */ /* JADX WARNING: Removed duplicated region for block: B:75:0x0114 A[SYNTHETIC, Splitter:B:75:0x0114] */ /* JADX WARNING: Removed duplicated region for block: B:80:0x011e A[SYNTHETIC, Splitter:B:80:0x011e] */ private String loadSourceFromUri(String str) { RandomAccessFile randomAccessFile; Throwable th; InputStream inputStream; Throwable th2; RandomAccessFile randomAccessFile2; Exception e; InputStream inputStream2; String str2 = "/"; InputStream inputStream3 = null; if (str == null || str.equals("")) { return null; } if (new File(str).exists()) { return str; } try { Matcher matcher = Pattern.compile("(.*?)://(.*)").matcher(str); if (matcher.find()) { String group = matcher.group(1); String group2 = matcher.group(2); if (group.equalsIgnoreCase("file")) { inputStream = new FileInputStream(group2); } else { if (!group.equalsIgnoreCase("asset")) { if (!group.equalsIgnoreCase("assets")) { inputStream = group.equalsIgnoreCase("res") ? getClass().getResourceAsStream(group2) : null; } } if (group2.startsWith(str2)) { str2 = ""; } inputStream = getClass().getResourceAsStream("/assets" + str2 + group2); } if (inputStream != null) { try { byte[] bArr = new byte[1024]; File file = new File(this.context.getFilesDir().getAbsolutePath() + group2); randomAccessFile = new RandomAccessFile(file, "rw"); while (true) { try { int read = inputStream.read(bArr); if (read <= 0) { break; } randomAccessFile.write(bArr, 0, read); } catch (Exception e2) { randomAccessFile2 = randomAccessFile; e = e2; inputStream2 = inputStream; try { e.printStackTrace(); if (inputStream2 != null) { } if (randomAccessFile2 != null) { } return null; } catch (Throwable th3) { th2 = th3; inputStream3 = inputStream2; th = th2; randomAccessFile = randomAccessFile2; inputStream = inputStream3; if (inputStream != null) { } if (randomAccessFile != null) { } throw th; } } catch (Throwable th4) { th = th4; if (inputStream != null) { } if (randomAccessFile != null) { } throw th; } } String absolutePath = file.getAbsolutePath(); try { inputStream.close(); } catch (Exception e3) { e3.printStackTrace(); } try { randomAccessFile.close(); } catch (IOException e4) { e4.printStackTrace(); } return absolutePath; } catch (Exception e5) { e = e5; inputStream2 = inputStream; randomAccessFile2 = null; e.printStackTrace(); if (inputStream2 != null) { try { inputStream2.close(); } catch (Exception e6) { e6.printStackTrace(); } } if (randomAccessFile2 != null) { try { randomAccessFile2.close(); } catch (IOException e7) { e7.printStackTrace(); } } return null; } catch (Throwable th5) { th2 = th5; inputStream3 = inputStream; randomAccessFile2 = null; th = th2; randomAccessFile = randomAccessFile2; inputStream = inputStream3; if (inputStream != null) { try { inputStream.close(); } catch (Exception e8) { e8.printStackTrace(); } } if (randomAccessFile != null) { try { randomAccessFile.close(); } catch (IOException e9) { e9.printStackTrace(); } } throw th; } } else { throw new IOException("bad data source"); } } } catch (Exception e10) { e = e10; randomAccessFile2 = null; inputStream2 = null; e.printStackTrace(); if (inputStream2 != null) { } if (randomAccessFile2 != null) { } return null; } catch (Throwable th6) { th2 = th6; randomAccessFile2 = null; th = th2; randomAccessFile = randomAccessFile2; inputStream = inputStream3; if (inputStream != null) { } if (randomAccessFile != null) { } throw th; } return null; } private BDSErrorDescription postEvent(BDSErrorDescription bDSErrorDescription, String str) { BDSMessage bDSMessage = new BDSMessage(); if (str.contains(i1.q)) { bDSMessage.m_messageName = str.replace(i1.q, "wak"); } else { bDSMessage.m_messageName = str; } bDSMessage.m_messageParams = new HashMap<>(); this.mParams.optString(SpeechConstant.APP_NAME, Policy.app(this.context)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PLATFORM, BDSParamBase.objectParam("Android", "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SDK_VERSION, BDSParamBase.objectParam("C++ ASR core", "java.lang.String")); LogUtil.v(TAG, " wakeup postEvent to c++ cmd:" + str + " Message:" + bDSMessage.toString()); try { if (this.m_Wakeupcore.postMessage(bDSMessage) == 0) { return bDSErrorDescription; } BDSErrorDescription bDSErrorDescription2 = new BDSErrorDescription(); bDSErrorDescription2.errorCode = -2; bDSErrorDescription2.errorDomain = 1; bDSErrorDescription2.errorDescription = "JNI: readyParamsAsrStart Call to Native layer returned error! err"; return bDSErrorDescription2; } catch (Throwable th) { th.printStackTrace(); BDSErrorDescription bDSErrorDescription3 = new BDSErrorDescription(); bDSErrorDescription3.errorCode = -2; bDSErrorDescription3.errorDomain = 1; bDSErrorDescription3.errorDescription = "JNI: readyParamsWpStart Call to Native layer returned error! err"; return bDSErrorDescription3; } } /* JADX WARNING: Removed duplicated region for block: B:20:0x002b */ /* JADX WARNING: Removed duplicated region for block: B:25:0x0037 A[SYNTHETIC, Splitter:B:25:0x0037] */ /* JADX WARNING: Removed duplicated region for block: B:33:? A[RETURN, SYNTHETIC] */ private void saveOutFile(byte[] bArr) { Throwable th; IOException e; String str = this.outFile; if (str != null && !str.equals("") && bArr != null) { FileOutputStream fileOutputStream = null; try { FileOutputStream fileOutputStream2 = new FileOutputStream(this.outFile, true); try { fileOutputStream2.write(bArr); try { fileOutputStream2.close(); } catch (IOException e2) { e2.printStackTrace(); } } catch (IOException e3) { e = e3; fileOutputStream = fileOutputStream2; try { e.printStackTrace(); if (fileOutputStream == null) { } } catch (Throwable th2) { th = th2; fileOutputStream2 = fileOutputStream; if (fileOutputStream2 != null) { try { fileOutputStream2.close(); } catch (IOException e4) { e4.printStackTrace(); } } throw th; } } catch (Throwable th3) { th = th3; if (fileOutputStream2 != null) { } throw th; } } catch (IOException e5) { e = e5; e.printStackTrace(); if (fileOutputStream == null) { fileOutputStream.close(); } } } } /* JADX WARNING: Removed duplicated region for block: B:19:0x006e */ /* JADX WARNING: Removed duplicated region for block: B:33:0x00af */ public BDSErrorDescription postEvent(String str, String str2) { BDSErrorDescription bDSErrorDescription; int i = 1; LogUtil.v(TAG, " wakeup postEvent cmd:" + str + " params:" + str2); try { if (!this.m_Wakeupcore.instanceInitialized()) { bDSErrorDescription = new BDSErrorDescription(); bDSErrorDescription.errorCode = -1; bDSErrorDescription.errorDomain = 1; bDSErrorDescription.errorDescription = "JNI: ASR Core native layer is not initialized!"; return bDSErrorDescription; } if (str2 != null) { try { if (!str2.equals("")) { this.mParams = new JSONObject(str2); if (!str.equals(SpeechConstant.WAKEUP_START)) { if (this.mIsWorking) { return null; } this.mIsWorking = true; try { if (!this.mParams.has("audio.socketport")) { String optString = this.mParams.optString(SpeechConstant.IN_FILE); if (this.mParams.has(SpeechConstant.AUDIO_SOURCE)) { i = this.mParams.optInt(SpeechConstant.AUDIO_SOURCE); } this.mParams.put("audio.socketport", MicrophoneServer.create(optString, i)); } } catch (Exception e) { e.printStackTrace(); } initWp(null, this.mParams); postEvent((BDSErrorDescription) null, WAK_CMD_LOAD_ENGINE); clearOutFile(); } else if (str.equals(SpeechConstant.WAKEUP_STOP)) { postEvent((BDSErrorDescription) null, WAK_CMD_UNLOAD_ENGINE); } return postEvent((BDSErrorDescription) null, str); } } catch (JSONException e2) { e2.printStackTrace(); this.mParams = new JSONObject(); } } this.mParams = new JSONObject(); if (!str.equals(SpeechConstant.WAKEUP_START)) { } return postEvent((BDSErrorDescription) null, str); } catch (Throwable th) { th.printStackTrace(); bDSErrorDescription = new BDSErrorDescription(); } } @Override // com.baidu.speech.core.BDSSDKLoader.BDSCoreEventListener public void receiveCoreEvent(BDSMessage bDSMessage, BDSSDKLoader.BDSSDKInterface bDSSDKInterface) { EventListener eventListener = this.mListener; if (eventListener != null && bDSMessage != null) { asrCallBack(bDSMessage, eventListener); } } public void setListener(EventListener eventListener) { this.mListener = eventListener; } }