package com.baidu.speech.core; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.AssetFileDescriptor; import android.media.MediaPlayer; import android.net.Uri; import android.text.TextUtils; import android.util.Log; import com.baidu.speech.asr.ASRListener; import com.baidu.speech.asr.EventContext; import com.baidu.speech.asr.SpeechConstant; import com.baidu.speech.audio.MicrophoneServer; import com.baidu.speech.core.BDSParamBase; import com.baidu.speech.core.BDSSDKLoader; import com.baidu.speech.utils.AsrError; import com.baidu.speech.utils.CommonParam; import com.baidu.speech.utils.LogUtil; import com.baidu.speech.utils.Policy; import com.baidu.speech.utils.Utility; import com.baidu.speech.utils.analysis.Analysis; import com.nordnetab.chcp.main.config.ContentManifest; import com.nordnetab.chcp.main.js.PluginResultHelper; 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.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.UUID; import java.util.Vector; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class ASREngine implements BDSSDKLoader.BDSCoreEventListener { private static String ASR_CMD_CANCEL = "asr.cancel"; private static String ASR_CMD_CONFIG = "asr.config"; private static String ASR_CMD_LOAD_ENGINE = "asr.kws.load"; private static String ASR_CMD_START = "asr.start"; private static String ASR_CMD_STOP = "asr.stop"; private static String ASR_CMD_UNLOAD_ENGINE = "asr.kws.unload"; private static String ASR_CMD_UPLOAD_CANCEL = "asr.upload.cancel"; private static String ASR_CMD_UPLOAD_CONTRACT = "asr.upload.contract"; private static String ASR_CMD_UPLOAD_WORDS = "asr.upload.words"; private static String ASR_PARAM_KEY_ACCEPT_AUDIO_DATA = "asr_param_key_accept_audio_data.bool"; private static String ASR_PARAM_KEY_API_SECRET_KEYS = "asr_param_key_api_secret_key.vector<string>"; private static String ASR_PARAM_KEY_APP = "asr_param_key_app.string"; private static String ASR_PARAM_KEY_AUDIO_FILE_PATH = "mic_audio_file_path.string"; private static String ASR_PARAM_KEY_AUDIO_mills = "mic_audio_mills.string"; private static String ASR_PARAM_KEY_BROWSER_USER_AGENT = "asr_param_key_browser_user_agent.string"; private static String ASR_PARAM_KEY_BUA = "asr_param_key_bua.string"; private static String ASR_PARAM_KEY_CHUNK_ENABLE = "asr_param_key_chunk_enable.bool"; private static String ASR_PARAM_KEY_CHUNK_KEY = "asr_param_key_chunk_key.string"; private static String ASR_PARAM_KEY_CHUNK_PARAM = "asr_param_key_chunk_param.string"; private static String ASR_PARAM_KEY_CHUNK_TTS = "asr_param_key_chunk_tts.string"; private static String ASR_PARAM_KEY_CITY_ID = "asr_param_key_city_id.int"; private static String ASR_PARAM_KEY_COK = "asr_param_key_cok.string"; private static String ASR_PARAM_KEY_COMPRESSION_TYPE = "asr_param_key_compression_type.int"; private static String ASR_PARAM_KEY_DEV = "asr_param_key_dev.string"; private static String ASR_PARAM_KEY_DISABLE_PUNCTUATION = "asr_param_key_disable_punctuation.bool"; private static String ASR_PARAM_KEY_DNN_HEAD_SIL_DURATION = "asr_param_key_dnn_head_sil_duration.int"; private static String ASR_PARAM_KEY_DNN_MIN_SP_DURATION = "asr_param_key_dnn_min_sp_duration.int"; private static String ASR_PARAM_KEY_DNN_SIL_THRESHOLD = "asr_param_key_dnn_sil_threshold.float"; private static String ASR_PARAM_KEY_DNN_SPEECH_THRESHOLD = "asr_param_key_dnn_speech_threshold.float"; private static String ASR_PARAM_KEY_ENABLE_CONTACTS = "asr_param_key_enable_contacts.bool"; private static String ASR_PARAM_KEY_ENABLE_DRC = "asr_param_key_enable_drc.bool"; private static String ASR_PARAM_KEY_ENABLE_EARLY_RETURN = "asr_param_key_enable_early_return.bool"; private static String ASR_PARAM_KEY_ENABLE_HTTPDNS = "asr_param_key_enable_httpdns.bool"; private static String ASR_PARAM_KEY_ENABLE_LOCAL_VAD = "asr_param_key_enable_local_vad.bool"; private static String ASR_PARAM_KEY_ENABLE_LONG_SPEECH = "asr_param_key_enable_long_speech.bool"; private static String ASR_PARAM_KEY_ENABLE_MODEL_VAD = "asr_param_key_enable_model_vad.int"; private static String ASR_PARAM_KEY_ENABLE_NLU = "asr_param_key_enable_nlu.bool"; private static String ASR_PARAM_KEY_ENABLE_NUMBERFORMAT = "asr_param_key_enable_numberformat.bool"; private static String ASR_PARAM_KEY_ENABLE_SERVER_VAD = "asr_param_key_enable_server_vad.bool"; private static String ASR_PARAM_KEY_FRM = "asr_param_key_frm.string"; private static String ASR_PARAM_KEY_GLB = "asr_param_key_glb.string"; private static String ASR_PARAM_KEY_KWS_PROTOCOL = "asr_param_key_kws_protocol.int"; private static String ASR_PARAM_KEY_LANGUAGE = "asr_param_key_language.int"; private static String ASR_PARAM_KEY_LM_ID = "asr_param_key_lm_id.int"; private static String ASR_PARAM_KEY_LTP = "asr_param_key_ltp.string"; private static String ASR_PARAM_KEY_MAX_WAIT_DURATION = "asr_param_key_max_wait_duration.int"; private static String ASR_PARAM_KEY_MODEL_VAD_DAT_FILE = "asr_param_key_model_vad_dat_file.string"; private static String ASR_PARAM_KEY_MULTI_START_AND_END = "asr_param_key_multi_start_and_end.bool"; private static String ASR_PARAM_KEY_NETWORK_STATUS = "asr_param_key_network_status.int"; private static String ASR_PARAM_KEY_OFFLINE_APP_CODE = "offline_param_key_app_code.string"; private static String ASR_PARAM_KEY_OFFLINE_ENGINE_DAT_FILE_PATH = "kws_param_key_dat_filepath.string"; private static String ASR_PARAM_KEY_OFFLINE_ENGINE_GRAMMER_FILE_PATH = "kws_param_key_grammer_filepath.string"; private static String ASR_PARAM_KEY_OFFLINE_ENGINE_TYPE = "kws_param_key_type.int"; private static String ASR_PARAM_KEY_PAM = "asr_param_key_pam.string"; private static String ASR_PARAM_KEY_PLATFORM = "asr_param_key_platform.string"; private static String ASR_PARAM_KEY_PRODUCT_ID = "asr_param_key_product_id.string"; private static String ASR_PARAM_KEY_PROPERTY_LIST = "asr_param_key_property_list.vector<int>"; private static String ASR_PARAM_KEY_PROTOCOL = "asr_param_key_protocol.int"; private static String ASR_PARAM_KEY_PU = "asr_param_key_pu.string"; private static String ASR_PARAM_KEY_PUNCTUATION_EXT_MODE = "asr_param_key_punctuation_ext_mode.int"; private static String ASR_PARAM_KEY_REALTIME_DATA = "asr_param_key_realtime_data.string"; private static String ASR_PARAM_KEY_RSV = "asr_param_key_rsv.map<string,string>"; private static String ASR_PARAM_KEY_SAMPLE_RATE = "asr_param_key_sample_rate.int"; private static String ASR_PARAM_KEY_SDK_VERSION = "asr_param_key_sdk_version.string"; private static String ASR_PARAM_KEY_SERVER_AGENT_URL = "asr_param_key_server_agent_url.string"; private static String ASR_PARAM_KEY_SERVER_URL = "asr_param_key_server_url.string"; private static String ASR_PARAM_KEY_START_TONE = "asr_param_key_start_tone.int"; private static String ASR_PARAM_KEY_STC = "asr_param_key_stc.string"; private static String ASR_PARAM_KEY_STRATEGY = "asr_param_key_strategy.int"; private static String ASR_PARAM_KEY_TXT = "asr_param_key_txt.string"; private static String ASR_PARAM_KEY_UID_STRING = "uid.string"; private static String ASR_PARAM_KEY_VAD_ENABLE_LONG_PRESS = "vad_enable_long_press.bool"; private static String ASR_PARAM_KEY_VAD_ENDPOINT_TIMEOUT = "asr_param_key_vad_endpoint_timeout.int"; private static String BDS_ASR_OFFLINE_ENGINE_GRAMMER_SLOT = "kws_param_key_slot.string"; private static String BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD = "kws_param_key_triggered_wakeup_word.string"; private static String COMMON_PARAM_KEY_DEBUG_LOG_LEVEL = "common_param_key_debug_log_level.int"; private static final boolean DEBUG = true; public static final int ERROR_AUDIO = 3; public static final int ERROR_CLIENT = 5; public static final int ERROR_INSUFFICIENT_PERMISSIONS = 9; public static final int ERROR_NETWORK = 2; public static final int ERROR_NETWORK_TIMEOUT = 1; public static final int ERROR_NO_MATCH = 7; public static final int ERROR_RECOGNIZER_BUSY = 8; public static final int ERROR_SERVER = 4; public static final int ERROR_SPEECH_TIMEOUT = 6; private static final int EVoiceRecognitionClientWorkStatusCancel = 7; private static final int EVoiceRecognitionClientWorkStatusChunkEnd = 14; private static final int EVoiceRecognitionClientWorkStatusChunkNlu = 13; private static final int EVoiceRecognitionClientWorkStatusChunkThirdData = 12; private static final int EVoiceRecognitionClientWorkStatusChunkTtsData = 19; private static final int EVoiceRecognitionClientWorkStatusEnd = 2; private static final int EVoiceRecognitionClientWorkStatusError = 8; private static final int EVoiceRecognitionClientWorkStatusExit = 18; private static final int EVoiceRecognitionClientWorkStatusFinish = 5; private static final int EVoiceRecognitionClientWorkStatusFlushData = 4; private static final int EVoiceRecognitionClientWorkStatusLOG = 11; private static final int EVoiceRecognitionClientWorkStatusLoaded = 9; private static final int EVoiceRecognitionClientWorkStatusLongSpeechEnd = 17; private static final int EVoiceRecognitionClientWorkStatusMeterLevel = 6; private static final int EVoiceRecognitionClientWorkStatusNewRecordData = 3; private static final int EVoiceRecognitionClientWorkStatusStart = 1; private static final int EVoiceRecognitionClientWorkStatusStartWorkIng = 0; private static final int EVoiceRecognitionClientWorkStatusUnLoaded = 10; 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 = "ASREngine"; private static String UNIT_PARAM_BOT_SESSION_LIST = "bot_session_list.string"; private static boolean hasBegin = false; private static boolean hasEnd = false; private static boolean hasPartialResult = false; static final MediaPlayer player = new MediaPlayer(); private int decodertemp = 0; private boolean enableLongSpeech = false; private boolean isOfflineLast = false; private boolean isUnitFirstPackage = true; private String mApp; private boolean mCalledStop = false; private Context mContext = null; private boolean mEnableChunk = false; private boolean mEnableLogFeedBack = true; private boolean mEnableLongPress = false; private EventContext mEventContext; private boolean mExceptioned = false; private boolean mFeedBackAudio = false; private boolean mIsWorking = false; private String mLastRecognitionResult = ""; private ASRListener mListener; private Map<String, JSONObject> mOriginNlp = new HashMap(); private String mOutFile = null; private JSONObject mParams; private String mPlatform; private String mSerialNumber = ""; private int mStreamType = -1; private String mUserData = null; private String mVersion; private int mVolumeFeedbackCount = 0; private int mVolumeFreq = 5; private BDSSDKLoader.BDSSDKInterface m_ASRcore; private Future<JSONObject> nlpFeature; private ExecutorService nluBuilderThread = Executors.newSingleThreadExecutor(); private StringBuffer unitThirdBufferData; private JSONObject usingSimpleNlp; public ASREngine(Context context) throws Exception { this.mContext = context; this.mEventContext = new EventContext(context); try { BDSSDKLoader.loadLibraries(); try { this.m_ASRcore = BDSSDKLoader.getSDKObjectForSDKType("ASRCore", this.mContext); if (this.m_ASRcore == null) { throw new Exception("ASR core support is not linked in package"); } else if (this.m_ASRcore.instanceInitialized()) { this.m_ASRcore.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, null)); } } private String adaptiveOfflineResult(String str) { try { JSONObject jSONObject = new JSONObject(str).getJSONObject("origin_result"); if (!jSONObject.has("raw_text")) { return str; } return new JSONObject(str).put("results_recognition", new JSONArray().put(jSONObject.getString("raw_text"))).toString(); } catch (JSONException e) { e.printStackTrace(); return str; } } private void asrCallBack(BDSMessage bDSMessage, ASRListener aSRListener) { String str; String str2; JSONObject jSONObject; int i; int i2; byte[] bArr; String str3; String str4; ASRListener aSRListener2; String generateNluResult; byte[] bArr2; String str5; int i3; int length; if (bDSMessage.m_messageName.equals(SpeechConstant.ASR_CALLBACk_NAME)) { boolean z = true; LogUtil.v(TAG, "ASRCallBack :" + bDSMessage.toString()); int i4 = ((BDSParamBase.BDSIntParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ASR_STATUS)).iValue; Log.v(TAG, "ASRCallBack :" + i4); switch (i4) { case 0: hasBegin = false; hasPartialResult = false; hasEnd = false; str = (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ASR_RESULT)).iValue; str2 = SpeechConstant.CALLBACK_EVENT_ASR_READY; aSRListener.onEvent(str2, str, null, 0, 0); return; case 1: this.mSerialNumber = (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ASR_RESULT)).iValue; HashMap hashMap = new HashMap(); hashMap.put("sn", this.mSerialNumber); aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_SERIALNUMBER, new JSONObject(hashMap).toString(), null, 0, 0); if (!hasBegin) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_BEGIN, null, null, 0, 0); hasBegin = true; return; } return; case 2: if (!hasEnd) { play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_END, -1)), false); try { JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("vad_silent_start", (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ASR_RESULT)).iValue); aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_END, jSONObject2.toString(), null, 0, 0); hasEnd = true; hasBegin = true; return; } catch (JSONException e) { e.printStackTrace(); return; } } else { return; } case 3: byte[] bArr3 = bDSMessage.m_messageData; if (this.mFeedBackAudio && bArr3 != null) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_AUDIO, null, bArr3, 0, bArr3.length); } saveOutFile(bArr3); return; case 4: hasPartialResult = true; if (!hasBegin) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_BEGIN, null, null, 0, 0); hasBegin = true; } String str6 = (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ASR_RESULT)).iValue; this.mLastRecognitionResult = str6; str = generateChunkPartialResult(adaptiveOfflineResult(str6)); str2 = SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL; aSRListener.onEvent(str2, str, null, 0, 0); return; case 5: if (!hasEnd) { play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_END, -1)), false); aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_END, null, null, 0, 0); hasEnd = true; } play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_SUCCESS, -1)), false); this.mLastRecognitionResult = ""; String adaptiveOfflineResult = adaptiveOfflineResult((String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ASR_RESULT)).iValue); try { if (new JSONObject(adaptiveOfflineResult).optJSONArray("results_recognition").length() != 0) { z = false; } } catch (JSONException unused) { } if (z) { play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_ERROR, -1)), false); try { JSONObject jSONObject3 = new JSONObject(); JSONObject jSONObject4 = new JSONObject(); jSONObject4.put("sn", this.mSerialNumber); jSONObject4.put(PluginResultHelper.JsParams.General.ERROR, 7); jSONObject3.put("desc", "Speech Quality Problem"); jSONObject3.put("origin_result", jSONObject4); jSONObject3.put(PluginResultHelper.JsParams.General.ERROR, 7); jSONObject3.put("desc", "Speech Quality Problem"); aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, jSONObject3.toString(), null, 0, 0, true); this.mIsWorking = false; return; } catch (Exception e2) { e2.printStackTrace(); return; } } else { String generateChunkFinalResult = generateChunkFinalResult(adaptiveOfflineResult); if (this.mEnableChunk) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL, generateChunkFinalResult, null, 0, 0, true); if (this.isOfflineLast) { HashMap hashMap2 = new HashMap(); hashMap2.put(PluginResultHelper.JsParams.General.ERROR, 0); hashMap2.put("desc", "Speech Recognize success."); HashMap hashMap3 = new HashMap(); hashMap3.put("err_no", 0); hashMap3.put(PluginResultHelper.JsParams.General.ERROR, "Speech Recognize success."); hashMap2.put("origin_result", new JSONObject(hashMap3)); aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, new JSONObject(hashMap2).toString(), null, 0, 0); this.mIsWorking = false; this.isOfflineLast = false; } else if (this.enableLongSpeech) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, generateEndResult(generateChunkFinalResult.replaceAll("^.*\"sn\": ?\"(.+)\".*$", "$1")), null, 0, 0); } } else { try { jSONObject = new JSONObject(generateChunkFinalResult); jSONObject.put("desc", "success"); jSONObject.put(PluginResultHelper.JsParams.General.ERROR, 0); } catch (Exception e3) { e3.printStackTrace(); jSONObject = new JSONObject(); } aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, jSONObject.toString(), null, 0, 0, true); this.mIsWorking = false; } hasPartialResult = false; return; } case 6: this.mVolumeFeedbackCount++; if (this.mVolumeFeedbackCount % this.mVolumeFreq == 0) { int i5 = ((BDSParamBase.BDSIntParam) bDSMessage.m_messageParams.get(SpeechConstant.strCALLBACK_ASR_LEVEL)).iValue / 100; HashMap hashMap4 = new HashMap(); hashMap4.put("volume", Integer.valueOf(i5)); hashMap4.put("volume-percent", Integer.valueOf((int) (Math.min(5000.0f, (float) i5) / 50.0f))); aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_VOLUME, new JSONObject(hashMap4).toString(), null, 0, 0); return; } return; case 7: play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_CANCEL, -1)), false); aSRListener.onEvent("asr.cancel", null, null, 0, 0); hasBegin = false; return; case 8: play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_ERROR, -1)), false); hasBegin = false; int i6 = ((BDSParamBase.BDSIntParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ERROR_DOMAIN)).iValue; String str7 = (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ERROR_DESC)).iValue; int i7 = ((BDSParamBase.BDSIntParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ERROR_CODE)).iValue; String str8 = ""; Log.isLoggable(TAG, 3); Log.e(TAG, "EVoiceRecognitionClientWorkStatusError errorDomain : " + i6 + " errorCode : " + i7 + " desc : " + str7 + " mLastRecognitionResult: " + this.mLastRecognitionResult); if (this.mLastRecognitionResult.isEmpty() || i6 != 20 || i7 == 1 || !hasPartialResult) { try { str8 = generateErrorResult(i6, i7, str7); } catch (Exception unused2) { } aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, str8, null, 0, 0); this.mIsWorking = false; return; } play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_END, -1)), false); aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_END, null, null, 0, 0); if (this.mEnableChunk) { bArr = null; i2 = 0; i = 0; aSRListener2 = aSRListener; aSRListener2.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL, generateChunkFinalResult(this.mLastRecognitionResult), null, 0, 0, true); play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_SUCCESS, -1)), false); str3 = generateEndResult(this.mSerialNumber); str4 = SpeechConstant.CALLBACK_EVENT_ASR_FINISH; } else { play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_SUCCESS, -1)), false); str4 = SpeechConstant.CALLBACK_EVENT_ASR_FINISH; str3 = this.mLastRecognitionResult; bArr = null; i2 = 0; i = 0; aSRListener2 = aSRListener; } aSRListener2.onEvent(str4, str3, bArr, i2, i); this.mIsWorking = false; return; case 9: str2 = SpeechConstant.CALLBACK_EVENT_ASR_LOADED; str = null; aSRListener.onEvent(str2, str, null, 0, 0); return; case 10: aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_UNLOADED, null, null, 0, 0); return; case 11: if (this.mEnableLogFeedBack) { str = (String) ((BDSParamBase.BDSObjectParam) bDSMessage.m_messageParams.get(SpeechConstant.CALLBACK_ASR_RESULT)).iValue; str2 = SpeechConstant.CALLBACK_EVENT_ASR_LOG; aSRListener.onEvent(str2, str, null, 0, 0); return; } return; case 12: if (this.mEnableChunk) { String generateThirdResult = generateThirdResult(); byte[] bArr4 = bDSMessage.m_messageData; byte[] bArr5 = new byte[8]; for (int i8 = 0; i8 < 8; i8++) { bArr5[i8] = bArr4[i8 + 4]; } if (checkThirdDataUnit(new String(bArr5))) { LogUtil.d(TAG, "unit data"); String unitString = getUnitString(bArr4, generateThirdResult); if (bArr4.length <= 12) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_UNIT_FINISH, unitString, bArr4, 0, bArr4.length); return; } return; } else if (bArr4 != null) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL, generateThirdResult, bArr4, 0, bArr4.length); return; } else { return; } } else { return; } case 13: if (this.mEnableChunk) { generateNluResult = generateNluResult(); bArr2 = bDSMessage.m_messageData; if (bArr2 != null) { str5 = SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL; i3 = 0; length = bArr2.length; aSRListener.onEvent(str5, generateNluResult, bArr2, i3, length); return; } return; } return; case 14: if (!this.enableLongSpeech) { aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, generateEndResult(this.mSerialNumber), null, 0, 0); this.mIsWorking = false; play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_SUCCESS, -1)), false); return; } boolean z2 = this.mCalledStop; return; case 15: case 16: default: return; case 17: aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_LONG_SPEECH, null, null, 0, 0); this.mIsWorking = false; return; case 18: aSRListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_EXIT, null, null, 0, 0); return; case 19: if (this.mEnableChunk) { generateNluResult = generateTtsResult(); bArr2 = bDSMessage.m_messageData; if (bArr2 != null) { str5 = SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL; i3 = 0; length = bArr2.length; aSRListener.onEvent(str5, generateNluResult, bArr2, i3, length); return; } return; } return; } } } private boolean checkThirdDataUnit(String str) { if (!str.contains("unit")) { return false; } LogUtil.d(TAG, "unit data"); return true; } /* JADX WARNING: Removed duplicated region for block: B:22:0x0036 */ /* JADX WARNING: Removed duplicated region for block: B:25:0x003d A[SYNTHETIC, Splitter:B:25:0x003d] */ /* JADX WARNING: Removed duplicated region for block: B:33:? A[RETURN, SYNTHETIC] */ private void clearOutFile() { FileOutputStream fileOutputStream; Throwable th; IOException e; String str = this.mOutFile; if (str != null && !str.equals("")) { try { fileOutputStream = new FileOutputStream(this.mOutFile); try { fileOutputStream.write("".getBytes()); try { fileOutputStream.close(); } catch (IOException e2) { e2.printStackTrace(); } } catch (IOException e3) { e = e3; try { e.printStackTrace(); if (fileOutputStream == null) { fileOutputStream.close(); } } catch (Throwable th2) { th = th2; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e4) { e4.printStackTrace(); } } throw th; } } } catch (IOException e5) { fileOutputStream = null; e = e5; e.printStackTrace(); if (fileOutputStream == null) { } } catch (Throwable th3) { fileOutputStream = null; th = th3; if (fileOutputStream != null) { } throw th; } } } private void fillNlpResult(String str, JSONObject jSONObject) throws Exception { JSONArray optJSONArray; JSONArray optJSONArray2; String str2; String str3; Future<JSONObject> future = this.nlpFeature; if (future != null) { this.usingSimpleNlp = future.get(); this.nlpFeature = null; } if (this.usingSimpleNlp != null) { char c = 0; if (!(jSONObject.optInt(PluginResultHelper.JsParams.General.ERROR, 0) != 0 || (optJSONArray = jSONObject.optJSONArray("results_recognition")) == null || optJSONArray.length() == 0)) { String optString = optJSONArray.optString(0); if (!TextUtils.isEmpty(optString) && !TextUtils.isEmpty(str) && optString.length() > str.length()) { optString = optString.substring(str.length()); } JSONArray jSONArray = new JSONArray(); JSONObject jSONObject2 = this.usingSimpleNlp.getJSONObject("rules"); Iterator<String> keys = jSONObject2.keys(); while (keys.hasNext()) { String next = keys.next(); JSONArray jSONArray2 = jSONObject2.getJSONArray(next); int i = 0; while (i < jSONArray2.length()) { JSONObject jSONObject3 = jSONArray2.getJSONObject(i); String string = jSONObject3.getString("pattern"); JSONArray jSONArray3 = jSONObject3.getJSONArray("groups"); Matcher matcher = Pattern.compile(string).matcher(optString); while (matcher.find()) { JSONObject jSONObject4 = new JSONObject(); String[] split = next.split("\\."); if (split.length >= 2) { str2 = split[c]; str3 = split[1]; } else { str3 = next; str2 = str3; } jSONObject4.put("domain", str2); jSONObject4.put("intent", str3); jSONObject4.put("parser", "bsg"); JSONObject jSONObject5 = new JSONObject(); jSONObject4.put("object", jSONObject5); int groupCount = matcher.groupCount(); int i2 = 0; while (i2 < groupCount) { String string2 = jSONArray3.getString(i2); i2++; jSONObject5.put(string2, matcher.group(i2)); jSONObject2 = jSONObject2; } jSONArray.put(jSONObject4); c = 0; } i++; c = 0; } } String str4 = (String) this.mEventContext.searchItemFromJson(new JSONObject(jSONObject.optString("origin_result")), "json_res"); if (!TextUtils.isEmpty(str4) && (optJSONArray2 = new JSONObject(str4).optJSONArray("results")) != null) { for (int i3 = 0; i3 < optJSONArray2.length(); i3++) { jSONArray.put(optJSONArray2.getJSONObject(i3)); } } JSONObject jSONObject6 = new JSONObject(); jSONObject6.put("raw_text", optString); jSONObject6.put("results", jSONArray); jSONObject.put("results_nlu", jSONObject6); } } } private String generateChunkFinalResult(String str) { JSONArray optJSONArray; String str2 = ""; if (str == null) { str = ""; } try { JSONObject optJSONObject = new JSONObject(str).optJSONObject("origin_result"); String str3 = ""; if (optJSONObject != null) { if (optJSONObject.optJSONObject("result") != null) { if (optJSONObject.optJSONObject("result").optJSONArray("word") != null) { optJSONArray = optJSONObject.optJSONObject("result").optJSONArray("word"); } else if (!(optJSONObject.optJSONObject("content") == null || optJSONObject.optJSONObject("content").optJSONArray("item") == null)) { optJSONArray = optJSONObject.optJSONObject("content").optJSONArray("item"); } str3 = optJSONArray.optString(0); } if (optJSONObject.has("raw_text")) { str3 = optJSONObject.optString("raw_text"); if (isIllegalResult(str3)) { str3 = str3.replace("1。00。", ""); } } else { if (!(optJSONObject.optJSONObject("result") == null || optJSONObject.optJSONObject("result").optString("raw_text") == null || !"KWS".equals(optJSONObject.optJSONObject("result").optString("sn")))) { str3 = optJSONObject.optJSONObject("result").optString("raw_text"); } if (this.mParams != null && ("enable".equals(this.mParams.optString(SpeechConstant.NLU)) || "enable-all".equals(this.mParams.optString(SpeechConstant.NLU)))) { str2 = getNlpResult(this.mParams.optString("keyword"), new JSONObject(str)); } } this.isOfflineLast = true; str2 = getNlpResult(this.mParams.optString("keyword"), new JSONObject(str)); } if (str3 == null) { str3 = ""; } HashMap hashMap = new HashMap(); hashMap.put("result_type", "final_result"); hashMap.put("best_result", str3); hashMap.put("origin_result", optJSONObject); hashMap.put(PluginResultHelper.JsParams.General.ERROR, 0); hashMap.put("results_recognition", new JSONArray().put(str3)); if (!TextUtils.isEmpty(str2)) { hashMap.put("results_nlu", str2); } return new JSONObject(hashMap).toString(); } catch (Exception e) { e.printStackTrace(); return ""; } } private String generateChunkPartialResult(String str) { JSONArray optJSONArray; String str2 = ""; if (str == null) { str = ""; } try { JSONObject optJSONObject = new JSONObject(str).optJSONObject("origin_result"); String str3 = ""; if (optJSONObject != null) { if (optJSONObject.optJSONObject("result") != null) { if (optJSONObject.optJSONObject("result").optJSONArray("word") != null) { optJSONArray = optJSONObject.optJSONObject("result").optJSONArray("word"); } else if (!(optJSONObject.optJSONObject("content") == null || optJSONObject.optJSONObject("content").optJSONArray("item") == null)) { optJSONArray = optJSONObject.optJSONObject("content").optJSONArray("item"); } str3 = optJSONArray.optString(0); } if (optJSONObject.has("raw_text")) { str3 = optJSONObject.optString("raw_text"); if (isIllegalResult(str3)) { str3 = str3.replace("1。00。", ""); } } else if (!(optJSONObject.optJSONObject("result") == null || optJSONObject.optJSONObject("result").optString("raw_text") == null || !"KWS".equals(optJSONObject.optJSONObject("result").optString("sn")))) { str3 = optJSONObject.optJSONObject("result").optString("raw_text"); } } if (this.mParams != null && "enable-all".equals(this.mParams.optString(SpeechConstant.NLU))) { str2 = getNlpResult(this.mParams.optString("keyword"), new JSONObject(str)); } if (str3 == null) { str3 = ""; } HashMap hashMap = new HashMap(); hashMap.put("result_type", "partial_result"); hashMap.put("best_result", str3); hashMap.put("origin_result", optJSONObject); hashMap.put(PluginResultHelper.JsParams.General.ERROR, 0); hashMap.put("results_recognition", new JSONArray().put(str3)); if (!TextUtils.isEmpty(str2)) { hashMap.put("results_nlu", str2); } return new JSONObject(hashMap).toString(); } catch (Exception e) { e.printStackTrace(); return ""; } } private String generateEndResult(String str) { HashMap hashMap = new HashMap(); hashMap.put(PluginResultHelper.JsParams.General.ERROR, 0); hashMap.put("desc", "Speech Recognize success."); HashMap hashMap2 = new HashMap(); hashMap2.put("sn", str); hashMap2.put("err_no", 0); hashMap2.put(PluginResultHelper.JsParams.General.ERROR, "Speech Recognize success."); hashMap.put("origin_result", new JSONObject(hashMap2)); return new JSONObject(hashMap).toString(); } private String generateErrorResult(int i, int i2, String str) throws Exception { Log.isLoggable(TAG, 3); Log.d(TAG, "generateErrorResult errDomain = " + i + " errCode = " + i2); if (Utility.getWifiOr2gOr3G(this.mContext) == 0 && this.decodertemp == 0) { return generateErrorResult(AsrError.ERROR_NETWORK_NOT_AVAILABLE, null); } if (AsrError.getDescFromCode(i2) == null && i != 10) { if (i != 20) { if (i == 30) { if (i2 == 1) { i2 = AsrError.ERROR_ASR_ENGINE_BUSY; } else if (i2 != 2) { if (i2 == 3) { i2 = 5003; } else if (i2 == 4) { i2 = 5004; } } } else if (i != 31) { if (i != 32) { if (i == 33) { if (i2 == -3001) { i2 = AsrError.ERROR_SERVER_PARAM; } else if (i2 == -3002) { i2 = AsrError.ERROR_SERVER_BACKEND; } else if (i2 == -3003) { i2 = AsrError.ERROR_SERVER_RECOGNITION; } else if (i2 == -3004) { i2 = AsrError.ERROR_SERVER_APP; } else if (i2 != -3005) { if (i2 == -3006) { i2 = AsrError.ERROR_SPEECH_TOO_LONG; } } } else if (i == 34) { if (i2 == 1) { i2 = AsrError.ERROR_OFFLINE_EXCEPTION; } else if (i2 == 2) { i2 = AsrError.ERROR_OFFLINE_NO_LICENSE; } else if (i2 == 3) { i2 = AsrError.ERROR_OFFLINE_INVALID_LICENSE; } else if (i2 == 4) { i2 = AsrError.ERROR_OFFLINE_PARAM; } else if (i2 == 5) { i2 = AsrError.ERROR_OFFLINE_NOT_INITIAL; } else if (i2 == 6) { if (this.decodertemp != 4) { i2 = AsrError.ERROR_OFFLINE_INVALID_MODEL; } } else if (i2 == 7) { i2 = AsrError.ERROR_OFFLINE_INVALID_GRAMMAR; } else if (i2 == 8) { i2 = AsrError.ERROR_OFFLINE_ENGINE_RESET_FAIL; } else if (i2 == 9) { i2 = AsrError.ERROR_OFFLINE_ENGINE_INITIAL_FAIL; } else if (i2 == 10) { i2 = AsrError.ERROR_OFFLINE_ENGINE_FREE_FAIL; } else if (i2 == 11) { i2 = AsrError.ERROR_OFFLINE_ENGINE_NOT_SUPPORT; } else if (i2 == 12 && !hasPartialResult) { i2 = AsrError.ERROR_OFFLINE_RECOGNIZE_FAIL; } } i2 = AsrError.ERROR_NO_MATCH_RESULT; } } i2 = AsrError.ERROR_NETWORK_NOT_AVAILABLE; } else if (1 == i2) { i2 = AsrError.ERROR_AUDIO_VAD_INCORRECT; } else if (2 == i2 && !hasPartialResult) { i2 = AsrError.ERROR_AUDIO_VAD_NO_SPEECH; } else if (3 == i2 && !hasPartialResult) { i2 = AsrError.ERROR_AUDIO_VAD_SPEAK_TOO_SHORT; } i2 = -1; } return generateErrorResult(i2, str); } private String generateErrorResult(int i, String str) throws Exception { String str2; String str3 = ""; if (str == null || !str.contains("[") || !str.contains("]")) { str2 = AsrError.getDescFromCode(i); } else { try { String substring = str.substring(str.indexOf("["), str.length()); try { if (AsrError.getDescFromCode(i) != null) { str3 = AsrError.getDescFromCode(i).contains("null") ? "" : AsrError.getDescFromCode(i); } } catch (Exception e) { e.printStackTrace(); } str2 = str3 + substring; } catch (Exception e2) { e2.printStackTrace(); str2 = str3; } } int i2 = i / 1000; JSONObject jSONObject = new JSONObject(); JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("sn", this.mSerialNumber); jSONObject2.put(PluginResultHelper.JsParams.General.ERROR, i2); jSONObject2.put("desc", str2); jSONObject2.put("sub_error", i); jSONObject.put("origin_result", jSONObject2); jSONObject.put(PluginResultHelper.JsParams.General.ERROR, i2); jSONObject.put("desc", str2); jSONObject.put("sub_error", i); return jSONObject.toString(); } private String generateNluResult() { HashMap hashMap = new HashMap(); hashMap.put("result_type", "nlu_result"); hashMap.put("best_result", ""); hashMap.put("origin_result", ""); return new JSONObject(hashMap).toString(); } private String generateThirdResult() { HashMap hashMap = new HashMap(); hashMap.put("result_type", "third_result"); hashMap.put("best_result", ""); hashMap.put("origin_result", ""); return new JSONObject(hashMap).toString(); } private String generateTtsResult() { HashMap hashMap = new HashMap(); hashMap.put("result_type", "tts_result"); hashMap.put("best_result", ""); hashMap.put("origin_result", ""); return new JSONObject(hashMap).toString(); } private int getLanguageFlag(String str) { if (str == null || str.equals("") || str.equals("cmn-Hans-CN")) { return 0; } if (str.equals("yue-Hans-CN")) { return 1; } if (str.equals("en-GB")) { return 2; } return str.equals("sichuan-Hans-CN") ? 3 : 0; } private String getNlpResult(String str, JSONObject jSONObject) throws Exception { JSONArray optJSONArray; String str2; String str3; Future<JSONObject> future = this.nlpFeature; if (future != null) { this.usingSimpleNlp = future.get(); this.nlpFeature = null; } if (this.usingSimpleNlp == null) { return null; } char c = 0; if (jSONObject.optInt(PluginResultHelper.JsParams.General.ERROR, 0) != 0 || (optJSONArray = jSONObject.optJSONArray("results_recognition")) == null || optJSONArray.length() == 0) { return null; } String optString = optJSONArray.optString(0); if (!TextUtils.isEmpty(optString) && !TextUtils.isEmpty(str) && optString.length() > str.length()) { optString = optString.substring(str.length()); } JSONArray jSONArray = new JSONArray(); JSONObject jSONObject2 = this.usingSimpleNlp.getJSONObject("rules"); Iterator<String> keys = jSONObject2.keys(); while (keys.hasNext()) { String next = keys.next(); JSONArray jSONArray2 = jSONObject2.getJSONArray(next); int i = 0; while (i < jSONArray2.length()) { JSONObject jSONObject3 = jSONArray2.getJSONObject(i); String string = jSONObject3.getString("pattern"); JSONArray jSONArray3 = jSONObject3.getJSONArray("groups"); Matcher matcher = Pattern.compile(string).matcher(optString); while (matcher.find()) { JSONObject jSONObject4 = new JSONObject(); String[] split = next.split("\\."); if (split.length >= 2) { str2 = split[c]; str3 = split[1]; } else { str3 = next; str2 = str3; } jSONObject4.put("domain", str2); jSONObject4.put("intent", str3); jSONObject4.put("parser", "bsg"); JSONObject jSONObject5 = new JSONObject(); jSONObject4.put("object", jSONObject5); int groupCount = matcher.groupCount(); int i2 = 0; while (i2 < groupCount) { String string2 = jSONArray3.getString(i2); i2++; jSONObject5.put(string2, matcher.group(i2)); jSONObject2 = jSONObject2; } jSONArray.put(jSONObject4); c = 0; } i++; c = 0; } } String str4 = (String) this.mEventContext.searchItemFromJson(new JSONObject(jSONObject.optString("origin_result")), "json_res"); if (!TextUtils.isEmpty(str4)) { JSONArray jSONArray4 = (JSONArray) this.mEventContext.searchItemFromJson(new JSONObject(str4), "results"); if (jSONArray4 != null) { for (int i3 = 0; i3 < jSONArray4.length(); i3++) { jSONArray.put(jSONArray4.getJSONObject(i3)); } } } JSONObject jSONObject6 = new JSONObject(); jSONObject6.put("raw_text", optString); jSONObject6.put("results", jSONArray); return jSONObject6.toString(); } private int getSampleRateFlag(int i) { if (i == 8000) { return 1; } return i == 16000 ? 2 : 0; } private String getUnitString(byte[] bArr, String str) { if (!this.isUnitFirstPackage) { str = new String(bArr); if (str.length() > 0) { str = str.substring(12, str.length()); } this.unitThirdBufferData.append(str); } if (this.isUnitFirstPackage && bArr.length > 12) { this.isUnitFirstPackage = false; String str2 = new String(bArr); str = str2.substring(12, str2.length()); this.unitThirdBufferData = new StringBuffer(str); } if (bArr.length > 12) { return str; } this.isUnitFirstPackage = true; return this.unitThirdBufferData.toString(); } /* JADX WARNING: Removed duplicated region for block: B:102:0x05b9 */ /* JADX WARNING: Removed duplicated region for block: B:112:0x05dd */ /* JADX WARNING: Removed duplicated region for block: B:114:0x05f7 */ /* JADX WARNING: Removed duplicated region for block: B:120:0x06a3 */ /* JADX WARNING: Removed duplicated region for block: B:123:0x06e4 */ /* JADX WARNING: Removed duplicated region for block: B:124:0x06e6 */ /* JADX WARNING: Removed duplicated region for block: B:127:0x0713 */ /* JADX WARNING: Removed duplicated region for block: B:128:0x0716 */ /* JADX WARNING: Removed duplicated region for block: B:131:0x073f */ /* JADX WARNING: Removed duplicated region for block: B:132:0x0741 */ /* JADX WARNING: Removed duplicated region for block: B:135:0x0759 */ /* JADX WARNING: Removed duplicated region for block: B:143:0x07d4 */ /* JADX WARNING: Removed duplicated region for block: B:144:0x07d7 */ /* JADX WARNING: Removed duplicated region for block: B:146:0x07db */ /* JADX WARNING: Removed duplicated region for block: B:149:0x082a */ /* JADX WARNING: Removed duplicated region for block: B:157:0x08aa */ /* JADX WARNING: Removed duplicated region for block: B:162:0x08c0 A[Catch:{ Throwable -> 0x08e3 }] */ /* JADX WARNING: Removed duplicated region for block: B:164:0x08e2 A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:82:0x0431 */ /* JADX WARNING: Removed duplicated region for block: B:85:0x0438 */ /* JADX WARNING: Removed duplicated region for block: B:88:0x0453 */ /* JADX WARNING: Removed duplicated region for block: B:91:0x04a9 */ /* JADX WARNING: Removed duplicated region for block: B:99:0x0531 */ private BDSErrorDescription initConfig(BDSErrorDescription bDSErrorDescription, JSONObject jSONObject) throws Exception { String str; String optString; String optString2; JSONArray optJSONArray; int optInt; boolean optBoolean; String optString3; int postMessage; BDSParamBase bDSParamBase; String str2; HashMap<String, BDSParamBase> hashMap; Vector vector; String str3; HashMap<String, BDSParamBase> hashMap2; BDSParamBase bDSParamBase2; int i; BDSMessage bDSMessage = new BDSMessage(); bDSMessage.m_messageName = ASR_CMD_CONFIG; bDSMessage.m_messageParams = new HashMap<>(); ApplicationInfo applicationInfo = this.mContext.getPackageManager().getApplicationInfo(this.mContext.getPackageName(), 128); String optString4 = jSONObject.optString("decoder-server.pdt", jSONObject.optString(SpeechConstant.PID)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PRODUCT_ID, BDSParamBase.objectParam(optString4, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_LM_ID, BDSParamBase.intParam(jSONObject.optInt(SpeechConstant.LMID, 0))); bDSMessage.m_messageParams.put(UNIT_PARAM_BOT_SESSION_LIST, BDSParamBase.objectParam(jSONObject.optString(UNIT_PARAM_BOT_SESSION_LIST, jSONObject.optString(SpeechConstant.BOT_SESSION_LIST)), "java.lang.String")); String optString5 = jSONObject.optString("decoder-server.agent.url", jSONObject.optString("agent.url", "")); String str4 = null; if (TextUtils.isEmpty(optString4)) { String string = applicationInfo.metaData == null ? null : applicationInfo.metaData.getString("com.baidu.speech.API_KEY"); String string2 = applicationInfo.metaData == null ? "" : applicationInfo.metaData.getString("com.baidu.speech.SECRET_KEY"); String optString6 = jSONObject.optString(SpeechConstant.APP_KEY, jSONObject.optString("apikey", string)); String optString7 = jSONObject.optString(SpeechConstant.SECRET, string2); if (!(optString6 == null || optString7 == null)) { Vector vector2 = new Vector(); vector2.add(optString6); vector2.add(optString7); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_API_SECRET_KEYS, BDSParamBase.objectParam(vector2, "java.util.Vector;")); } } String optString8 = jSONObject.optString("decoder-server.fix-app", ""); String optString9 = jSONObject.optString(SpeechConstant.APP_NAME, Policy.app(this.mContext)); StringBuilder sb = new StringBuilder(); sb.append((optString8 == null || "".equals(optString8)) ? "" : optString8 + "/"); sb.append(optString9); this.mApp = sb.toString(); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_APP, BDSParamBase.objectParam(this.mApp, "java.lang.String")); if (!jSONObject.has(SpeechConstant.APP_KEY)) { String str5 = applicationInfo.metaData == null ? null : applicationInfo.metaData.getString("com.baidu.speech.API_KEY") + ""; if (!TextUtils.isEmpty(str5)) { jSONObject.put(SpeechConstant.APP_KEY, str5); } } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_KEY, BDSParamBase.objectParam(jSONObject.optString("decoder-server.key", jSONObject.optString(SpeechConstant.APP_KEY, "")), "java.lang.String")); if (applicationInfo.metaData != null) { str4 = applicationInfo.metaData.getInt("com.baidu.speech.APP_ID") + ""; } String optString10 = jSONObject.optString(SpeechConstant.APP_ID, str4); if (optString10 != null) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_OFFLINE_APP_CODE, BDSParamBase.objectParam(optString10, "java.lang.String")); } int optInt2 = jSONObject.optInt(SpeechConstant.LOG_LEVEL, -1); if (Log.isLoggable(LogUtil.LOGTAG, 3)) { optInt2 = 5; } else if (Log.isLoggable(LogUtil.LOGTAG, 2)) { optInt2 = 6; } if (optInt2 != -1) { bDSMessage.m_messageParams.put(COMMON_PARAM_KEY_DEBUG_LOG_LEVEL, BDSParamBase.intParam(optInt2)); } int optInt3 = jSONObject.optInt("basic.decoder", jSONObject.optInt(SpeechConstant.DECODER, 0)); this.decodertemp = optInt3; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_STRATEGY, BDSParamBase.intParam(optInt3)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SAMPLE_RATE, BDSParamBase.intParam(getSampleRateFlag(jSONObject.optInt("audio.sample", jSONObject.optInt(SpeechConstant.SAMPLE_RATE, 16000))))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_LANGUAGE, BDSParamBase.intParam(getLanguageFlag(jSONObject.optString("decoder-offline.language", jSONObject.optString(SpeechConstant.LANGUAGE, "cmn-Hans-CN"))))); String optString11 = jSONObject.optString(SpeechConstant.VAD, jSONObject.optString(SpeechConstant.VAD, SpeechConstant.VAD_DNN)); Log.isLoggable(TAG, 3); Log.e(TAG, "VAD Model=" + optString11); String format = String.format("%s/%s", this.mContext.getApplicationInfo().nativeLibraryDir, "libbd_easr_s1_merge_normal_20151216.dat.so"); String optString12 = jSONObject.optString(SpeechConstant.ASR_VAD_RES_FILE_PATH, jSONObject.optString("res-file", format)); if (optString11.equals(SpeechConstant.VAD_TOUCH)) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LOCAL_VAD, BDSParamBase.boolParam(false)); } else if (optString11.equals("input")) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LOCAL_VAD, BDSParamBase.boolParam(true)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_MODEL_VAD, BDSParamBase.intParam(0)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_MODEL_VAD_DAT_FILE, BDSParamBase.objectParam(loadSourceFromUri(optString12), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_VAD_ENDPOINT_TIMEOUT, BDSParamBase.intParam(jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, jSONObject.optInt("vad.end-frame", 2500)))); } else { if (optString11.equals(SpeechConstant.VAD_MODEL) || optString11.equals("model_vad")) { str = optString5; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LOCAL_VAD, BDSParamBase.boolParam(true)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_MODEL_VAD, BDSParamBase.intParam(1)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_MODEL_VAD_DAT_FILE, BDSParamBase.objectParam(loadSourceFromUri(optString12), "java.lang.String")); i = jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, jSONObject.optInt("vad.end-frame", 0)); } else { if (optString11.equals(SpeechConstant.VAD_DNN)) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LOCAL_VAD, BDSParamBase.boolParam(true)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_MODEL_VAD, BDSParamBase.intParam(2)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_MODEL_VAD_DAT_FILE, BDSParamBase.objectParam(this.mContext.getApplicationInfo().nativeLibraryDir, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_VAD_ENDPOINT_TIMEOUT, BDSParamBase.intParam(jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, jSONObject.optInt("vad.end-frame", 0)))); str = optString5; float optDouble = (float) jSONObject.optDouble("vad.speech-threshold", 0.0d); if (optDouble > 0.0f) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DNN_SPEECH_THRESHOLD, BDSParamBase.floatParam(optDouble)); } int optInt4 = jSONObject.optInt("vad.min-speech-duration", 0); if (optInt4 > 0) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DNN_MIN_SP_DURATION, BDSParamBase.intParam(optInt4)); } int optInt5 = jSONObject.optInt("vad.head-sil-duration", 0); if (optInt5 > 0) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DNN_HEAD_SIL_DURATION, BDSParamBase.intParam(optInt5)); } int optInt6 = jSONObject.optInt("vad.max-wait-duration", 0); if (optInt6 > 0) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_MAX_WAIT_DURATION, BDSParamBase.intParam(optInt6)); } float optDouble2 = (float) jSONObject.optDouble("vad.sil-threshold", 0.0d); if (optDouble2 > 0.0f) { hashMap2 = bDSMessage.m_messageParams; str3 = ASR_PARAM_KEY_DNN_SIL_THRESHOLD; bDSParamBase2 = BDSParamBase.floatParam(optDouble2); hashMap2.put(str3, bDSParamBase2); } } else { str = optString5; if (optString11.equals("search")) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LOCAL_VAD, BDSParamBase.boolParam(true)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_MODEL_VAD, BDSParamBase.intParam(0)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_MODEL_VAD_DAT_FILE, BDSParamBase.objectParam(loadSourceFromUri(optString12), "java.lang.String")); i = jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 1000); } else if (SpeechConstant.VAD_MFE.equals(optString11)) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LOCAL_VAD, BDSParamBase.boolParam(true)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_MODEL_VAD, BDSParamBase.intParam(0)); } } jSONObject.has(SpeechConstant.AUDIO_SOURCE); this.mVolumeFreq = jSONObject.optInt("mic.volume-freq", 5); if (this.mVolumeFreq <= 0) { this.mVolumeFreq = 1; } if (str != "") { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SERVER_AGENT_URL, BDSParamBase.objectParam(str, "java.lang.String")); } optString = jSONObject.optString(SpeechConstant.DEV, ""); if (!TextUtils.isEmpty(optString)) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DEV, BDSParamBase.objectParam(optString, "java.lang.String")); } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_AUDIO_FILE_PATH, BDSParamBase.objectParam(jSONObject.optString("audio.file", jSONObject.optString(SpeechConstant.IN_FILE, "")), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_AUDIO_mills, BDSParamBase.objectParam(jSONObject.optString(SpeechConstant.AUDIO_MILLS, ""), "java.lang.String")); bDSMessage.m_messageParams.put(MIC_PARAM_KEY_SOCKET_PORT, BDSParamBase.intParam(jSONObject.optInt("audio.socketport"))); if (jSONObject.has("audio.stream-type")) { this.mStreamType = jSONObject.optInt("audio.stream-type"); Log.isLoggable(TAG, 3); Log.d(TAG, "audio stream type = " + this.mStreamType); } bDSMessage.m_messageParams.put("mic_accept_audio_volume.bool", BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_VOLUME, true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_NETWORK_STATUS, BDSParamBase.intParam(Utility.getWifiOr2gOr3G(this.mContext))); String optString13 = jSONObject.optString(SpeechConstant.URL, jSONObject.optString("url", "https://vop.baidu.com/v2")); CommonParam.REQUEST_URL = new URL(optString13).getHost(); CommonParam.AGENT_URL = str; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SERVER_URL, BDSParamBase.objectParam(optString13, "java.lang.String")); optString2 = jSONObject.optString("decoder-server.uid", ""); jSONObject.optBoolean("inernational.bool", false); if (TextUtils.isEmpty(optString2)) { optString2 = Policy.uid(this.mContext); } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_UID_STRING, BDSParamBase.objectParam(optString2, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_GLB, BDSParamBase.objectParam(jSONObject.optString("decoder-server.glb", UUID.randomUUID().toString()), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_STC, BDSParamBase.objectParam(jSONObject.optString("decoder-server.stc"), "java.lang.String")); this.mPlatform = jSONObject.optString("decoder-server.pfm", Policy.pfm(this.mContext)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PLATFORM, BDSParamBase.objectParam(this.mPlatform, "java.lang.String")); this.mVersion = jSONObject.optString("decoder-server.ver", Policy.ver(this.mContext)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SDK_VERSION, BDSParamBase.objectParam(this.mVersion, "java.lang.String")); optJSONArray = jSONObject.optJSONArray(SpeechConstant.PROP); Vector vector3 = new Vector(); if (optJSONArray != null) { for (int i2 = 0; i2 < optJSONArray.length(); i2++) { try { vector3.add(Integer.valueOf(optJSONArray.getInt(i2))); } catch (JSONException e) { e.printStackTrace(); } } } if (optString11.equals("input")) { vector = new Vector(); } else if (vector3.size() > 0) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROPERTY_LIST, BDSParamBase.objectParam(vector3, "java.util.Vector;")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DISABLE_PUNCTUATION, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.disable-punctuation", jSONObject.optBoolean(SpeechConstant.DISABLE_PUNCTUATION, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PUNCTUATION_EXT_MODE, BDSParamBase.intParam(jSONObject.optInt(SpeechConstant.ASR_PUNCTUATION_MODE, 0))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_SERVER_VAD, BDSParamBase.boolParam(jSONObject.optBoolean("server-vad", true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_CONTACTS, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.contact", jSONObject.optBoolean(SpeechConstant.CONTACT, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_EARLY_RETURN, BDSParamBase.boolParam(jSONObject.optBoolean("enable-early-return", false))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NUMBERFORMAT, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ASR_ENABLE_NUMBERFORMAT, true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CITY_ID, BDSParamBase.intParam(jSONObject.optInt("cid"))); optInt = jSONObject.optInt("decoder-server.tts", jSONObject.optInt(Analysis.Item.TYPE_TTS, -1)); if (optInt != -1) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_TTS, BDSParamBase.objectParam(optInt + "", "java.lang.String")); } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_PARAM, BDSParamBase.objectParam(jSONObject.optString(SpeechConstant.PAM, ""), "java.lang.String")); this.mEnableChunk = 1 != jSONObject.optInt(SpeechConstant.DEC_TYPE, jSONObject.optInt("basic.dec-type", 1)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_ENABLE, BDSParamBase.boolParam(this.mEnableChunk)); boolean equals = jSONObject.optString(SpeechConstant.NLU, "disable").equals("enable"); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NLU, BDSParamBase.boolParam(equals)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-server.ptc", !equals ? 305 : 1))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_KWS_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-offline.ptc", 0))); this.enableLongSpeech = jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 1000) != 0; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LONG_SPEECH, BDSParamBase.boolParam(this.enableLongSpeech)); optBoolean = jSONObject.optBoolean("long-speech.multi-start-end", false); if (optBoolean) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_MULTI_START_AND_END, BDSParamBase.boolParam(optBoolean)); } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_HTTPDNS, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ENABLE_HTTPDNS, true))); optString3 = jSONObject.optString("keyword"); if (optString3 != null && !optString3.equals("")) { bDSMessage.m_messageParams.put(BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD, BDSParamBase.objectParam(optString3, "java.lang.String")); } String optString14 = jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH); String optString15 = jSONObject.optString("decoder-offline.asr-base-file-path", jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_DAT_FILE_PATH, jSONObject.optString("kws.res-file", jSONObject.optString("res-file", format)))); String optString16 = jSONObject.optString("decoder-offline.license-file-path", jSONObject.optString("license-file-path", jSONObject.optString("license"))); String optString17 = jSONObject.optString("decoder-offline.slot-data", jSONObject.optString(SpeechConstant.SLOT_DATA)); int i3 = TextUtils.isEmpty(optString14) ? 2 : 0; if (optInt3 != 0) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_OFFLINE_ENGINE_TYPE, BDSParamBase.intParam(i3)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_OFFLINE_ENGINE_GRAMMER_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString14), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_OFFLINE_ENGINE_DAT_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString15), "java.lang.String")); bDSMessage.m_messageParams.put(OFFLINE_PARAM_KEY_LICENSE_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString16), "java.lang.String")); bDSMessage.m_messageParams.put(BDS_ASR_OFFLINE_ENGINE_GRAMMER_SLOT, BDSParamBase.objectParam(optString17, "java.lang.String")); } if (SpeechConstant.PUBLIC_DECODER) { if (optString14 == null || optString14.equals("")) { hashMap = bDSMessage.m_messageParams; str2 = ASR_PARAM_KEY_STRATEGY; bDSParamBase = BDSParamBase.intParam(optInt3); } else { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_STRATEGY, BDSParamBase.intParam(optInt3)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_OFFLINE_ENGINE_DAT_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString15), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_OFFLINE_ENGINE_GRAMMER_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString14), "java.lang.String")); bDSMessage.m_messageParams.put(OFFLINE_PARAM_KEY_LICENSE_FILE_PATH, BDSParamBase.objectParam(loadSourceFromUri(optString16), "java.lang.String")); hashMap = bDSMessage.m_messageParams; str2 = BDS_ASR_OFFLINE_ENGINE_GRAMMER_SLOT; bDSParamBase = BDSParamBase.objectParam(optString17, "java.lang.String"); } hashMap.put(str2, bDSParamBase); } this.mOutFile = jSONObject.optString("audio.outfile", jSONObject.optString(SpeechConstant.OUT_FILE)); this.mEnableLogFeedBack = jSONObject.optBoolean("feedback-log", false); this.mFeedBackAudio = jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_DATA, false); if (this.mFeedBackAudio) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ACCEPT_AUDIO_DATA, BDSParamBase.boolParam(this.mFeedBackAudio)); } postMessage = this.m_ASRcore.postMessage(bDSMessage); if (postMessage != 0) { return bDSErrorDescription; } BDSErrorDescription bDSErrorDescription2 = new BDSErrorDescription(); bDSErrorDescription2.errorCode = -2; bDSErrorDescription2.errorDomain = 1; bDSErrorDescription2.errorDescription = "JNI: initConfig Call to Native layer returned error! err( " + postMessage + " )"; return bDSErrorDescription2; } else { vector = new Vector(); } vector.add(20000); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROPERTY_LIST, BDSParamBase.objectParam(vector, "java.util.Vector;")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DISABLE_PUNCTUATION, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.disable-punctuation", jSONObject.optBoolean(SpeechConstant.DISABLE_PUNCTUATION, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PUNCTUATION_EXT_MODE, BDSParamBase.intParam(jSONObject.optInt(SpeechConstant.ASR_PUNCTUATION_MODE, 0))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_SERVER_VAD, BDSParamBase.boolParam(jSONObject.optBoolean("server-vad", true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_CONTACTS, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.contact", jSONObject.optBoolean(SpeechConstant.CONTACT, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_EARLY_RETURN, BDSParamBase.boolParam(jSONObject.optBoolean("enable-early-return", false))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NUMBERFORMAT, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ASR_ENABLE_NUMBERFORMAT, true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CITY_ID, BDSParamBase.intParam(jSONObject.optInt("cid"))); optInt = jSONObject.optInt("decoder-server.tts", jSONObject.optInt(Analysis.Item.TYPE_TTS, -1)); if (optInt != -1) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_PARAM, BDSParamBase.objectParam(jSONObject.optString(SpeechConstant.PAM, ""), "java.lang.String")); this.mEnableChunk = 1 != jSONObject.optInt(SpeechConstant.DEC_TYPE, jSONObject.optInt("basic.dec-type", 1)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_ENABLE, BDSParamBase.boolParam(this.mEnableChunk)); boolean equals2 = jSONObject.optString(SpeechConstant.NLU, "disable").equals("enable"); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NLU, BDSParamBase.boolParam(equals2)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-server.ptc", !equals2 ? 305 : 1))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_KWS_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-offline.ptc", 0))); this.enableLongSpeech = jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 1000) != 0; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LONG_SPEECH, BDSParamBase.boolParam(this.enableLongSpeech)); optBoolean = jSONObject.optBoolean("long-speech.multi-start-end", false); if (optBoolean) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_HTTPDNS, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ENABLE_HTTPDNS, true))); optString3 = jSONObject.optString("keyword"); bDSMessage.m_messageParams.put(BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD, BDSParamBase.objectParam(optString3, "java.lang.String")); String optString142 = jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH); String optString152 = jSONObject.optString("decoder-offline.asr-base-file-path", jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_DAT_FILE_PATH, jSONObject.optString("kws.res-file", jSONObject.optString("res-file", format)))); String optString162 = jSONObject.optString("decoder-offline.license-file-path", jSONObject.optString("license-file-path", jSONObject.optString("license"))); String optString172 = jSONObject.optString("decoder-offline.slot-data", jSONObject.optString(SpeechConstant.SLOT_DATA)); if (TextUtils.isEmpty(optString142)) { } if (optInt3 != 0) { } if (SpeechConstant.PUBLIC_DECODER) { } this.mOutFile = jSONObject.optString("audio.outfile", jSONObject.optString(SpeechConstant.OUT_FILE)); this.mEnableLogFeedBack = jSONObject.optBoolean("feedback-log", false); this.mFeedBackAudio = jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_DATA, false); if (this.mFeedBackAudio) { } postMessage = this.m_ASRcore.postMessage(bDSMessage); if (postMessage != 0) { } } hashMap2 = bDSMessage.m_messageParams; str3 = ASR_PARAM_KEY_VAD_ENDPOINT_TIMEOUT; bDSParamBase2 = BDSParamBase.intParam(i); hashMap2.put(str3, bDSParamBase2); jSONObject.has(SpeechConstant.AUDIO_SOURCE); this.mVolumeFreq = jSONObject.optInt("mic.volume-freq", 5); if (this.mVolumeFreq <= 0) { } if (str != "") { } optString = jSONObject.optString(SpeechConstant.DEV, ""); if (!TextUtils.isEmpty(optString)) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_AUDIO_FILE_PATH, BDSParamBase.objectParam(jSONObject.optString("audio.file", jSONObject.optString(SpeechConstant.IN_FILE, "")), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_AUDIO_mills, BDSParamBase.objectParam(jSONObject.optString(SpeechConstant.AUDIO_MILLS, ""), "java.lang.String")); bDSMessage.m_messageParams.put(MIC_PARAM_KEY_SOCKET_PORT, BDSParamBase.intParam(jSONObject.optInt("audio.socketport"))); if (jSONObject.has("audio.stream-type")) { } bDSMessage.m_messageParams.put("mic_accept_audio_volume.bool", BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_VOLUME, true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_NETWORK_STATUS, BDSParamBase.intParam(Utility.getWifiOr2gOr3G(this.mContext))); String optString132 = jSONObject.optString(SpeechConstant.URL, jSONObject.optString("url", "https://vop.baidu.com/v2")); CommonParam.REQUEST_URL = new URL(optString132).getHost(); CommonParam.AGENT_URL = str; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SERVER_URL, BDSParamBase.objectParam(optString132, "java.lang.String")); optString2 = jSONObject.optString("decoder-server.uid", ""); jSONObject.optBoolean("inernational.bool", false); if (TextUtils.isEmpty(optString2)) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_UID_STRING, BDSParamBase.objectParam(optString2, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_GLB, BDSParamBase.objectParam(jSONObject.optString("decoder-server.glb", UUID.randomUUID().toString()), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_STC, BDSParamBase.objectParam(jSONObject.optString("decoder-server.stc"), "java.lang.String")); this.mPlatform = jSONObject.optString("decoder-server.pfm", Policy.pfm(this.mContext)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PLATFORM, BDSParamBase.objectParam(this.mPlatform, "java.lang.String")); this.mVersion = jSONObject.optString("decoder-server.ver", Policy.ver(this.mContext)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SDK_VERSION, BDSParamBase.objectParam(this.mVersion, "java.lang.String")); optJSONArray = jSONObject.optJSONArray(SpeechConstant.PROP); Vector vector32 = new Vector(); if (optJSONArray != null) { } if (optString11.equals("input")) { } vector.add(20000); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROPERTY_LIST, BDSParamBase.objectParam(vector, "java.util.Vector;")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DISABLE_PUNCTUATION, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.disable-punctuation", jSONObject.optBoolean(SpeechConstant.DISABLE_PUNCTUATION, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PUNCTUATION_EXT_MODE, BDSParamBase.intParam(jSONObject.optInt(SpeechConstant.ASR_PUNCTUATION_MODE, 0))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_SERVER_VAD, BDSParamBase.boolParam(jSONObject.optBoolean("server-vad", true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_CONTACTS, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.contact", jSONObject.optBoolean(SpeechConstant.CONTACT, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_EARLY_RETURN, BDSParamBase.boolParam(jSONObject.optBoolean("enable-early-return", false))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NUMBERFORMAT, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ASR_ENABLE_NUMBERFORMAT, true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CITY_ID, BDSParamBase.intParam(jSONObject.optInt("cid"))); optInt = jSONObject.optInt("decoder-server.tts", jSONObject.optInt(Analysis.Item.TYPE_TTS, -1)); if (optInt != -1) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_PARAM, BDSParamBase.objectParam(jSONObject.optString(SpeechConstant.PAM, ""), "java.lang.String")); this.mEnableChunk = 1 != jSONObject.optInt(SpeechConstant.DEC_TYPE, jSONObject.optInt("basic.dec-type", 1)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_ENABLE, BDSParamBase.boolParam(this.mEnableChunk)); boolean equals22 = jSONObject.optString(SpeechConstant.NLU, "disable").equals("enable"); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NLU, BDSParamBase.boolParam(equals22)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-server.ptc", !equals22 ? 305 : 1))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_KWS_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-offline.ptc", 0))); this.enableLongSpeech = jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 1000) != 0; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LONG_SPEECH, BDSParamBase.boolParam(this.enableLongSpeech)); optBoolean = jSONObject.optBoolean("long-speech.multi-start-end", false); if (optBoolean) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_HTTPDNS, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ENABLE_HTTPDNS, true))); optString3 = jSONObject.optString("keyword"); bDSMessage.m_messageParams.put(BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD, BDSParamBase.objectParam(optString3, "java.lang.String")); String optString1422 = jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH); String optString1522 = jSONObject.optString("decoder-offline.asr-base-file-path", jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_DAT_FILE_PATH, jSONObject.optString("kws.res-file", jSONObject.optString("res-file", format)))); String optString1622 = jSONObject.optString("decoder-offline.license-file-path", jSONObject.optString("license-file-path", jSONObject.optString("license"))); String optString1722 = jSONObject.optString("decoder-offline.slot-data", jSONObject.optString(SpeechConstant.SLOT_DATA)); if (TextUtils.isEmpty(optString1422)) { } if (optInt3 != 0) { } if (SpeechConstant.PUBLIC_DECODER) { } this.mOutFile = jSONObject.optString("audio.outfile", jSONObject.optString(SpeechConstant.OUT_FILE)); this.mEnableLogFeedBack = jSONObject.optBoolean("feedback-log", false); this.mFeedBackAudio = jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_DATA, false); if (this.mFeedBackAudio) { } postMessage = this.m_ASRcore.postMessage(bDSMessage); if (postMessage != 0) { } } str = optString5; jSONObject.has(SpeechConstant.AUDIO_SOURCE); this.mVolumeFreq = jSONObject.optInt("mic.volume-freq", 5); if (this.mVolumeFreq <= 0) { } if (str != "") { } optString = jSONObject.optString(SpeechConstant.DEV, ""); if (!TextUtils.isEmpty(optString)) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_AUDIO_FILE_PATH, BDSParamBase.objectParam(jSONObject.optString("audio.file", jSONObject.optString(SpeechConstant.IN_FILE, "")), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_AUDIO_mills, BDSParamBase.objectParam(jSONObject.optString(SpeechConstant.AUDIO_MILLS, ""), "java.lang.String")); bDSMessage.m_messageParams.put(MIC_PARAM_KEY_SOCKET_PORT, BDSParamBase.intParam(jSONObject.optInt("audio.socketport"))); if (jSONObject.has("audio.stream-type")) { } bDSMessage.m_messageParams.put("mic_accept_audio_volume.bool", BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_VOLUME, true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_NETWORK_STATUS, BDSParamBase.intParam(Utility.getWifiOr2gOr3G(this.mContext))); String optString1322 = jSONObject.optString(SpeechConstant.URL, jSONObject.optString("url", "https://vop.baidu.com/v2")); try { CommonParam.REQUEST_URL = new URL(optString1322).getHost(); } catch (MalformedURLException e2) { e2.printStackTrace(); } CommonParam.AGENT_URL = str; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SERVER_URL, BDSParamBase.objectParam(optString1322, "java.lang.String")); optString2 = jSONObject.optString("decoder-server.uid", ""); jSONObject.optBoolean("inernational.bool", false); if (TextUtils.isEmpty(optString2)) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_UID_STRING, BDSParamBase.objectParam(optString2, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_GLB, BDSParamBase.objectParam(jSONObject.optString("decoder-server.glb", UUID.randomUUID().toString()), "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_STC, BDSParamBase.objectParam(jSONObject.optString("decoder-server.stc"), "java.lang.String")); this.mPlatform = jSONObject.optString("decoder-server.pfm", Policy.pfm(this.mContext)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PLATFORM, BDSParamBase.objectParam(this.mPlatform, "java.lang.String")); this.mVersion = jSONObject.optString("decoder-server.ver", Policy.ver(this.mContext)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SDK_VERSION, BDSParamBase.objectParam(this.mVersion, "java.lang.String")); optJSONArray = jSONObject.optJSONArray(SpeechConstant.PROP); Vector vector322 = new Vector(); if (optJSONArray != null) { } if (optString11.equals("input")) { } vector.add(20000); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROPERTY_LIST, BDSParamBase.objectParam(vector, "java.util.Vector;")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_DISABLE_PUNCTUATION, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.disable-punctuation", jSONObject.optBoolean(SpeechConstant.DISABLE_PUNCTUATION, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PUNCTUATION_EXT_MODE, BDSParamBase.intParam(jSONObject.optInt(SpeechConstant.ASR_PUNCTUATION_MODE, 0))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_SERVER_VAD, BDSParamBase.boolParam(jSONObject.optBoolean("server-vad", true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_CONTACTS, BDSParamBase.boolParam(jSONObject.optBoolean("decoder-server-fun.contact", jSONObject.optBoolean(SpeechConstant.CONTACT, false)))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_EARLY_RETURN, BDSParamBase.boolParam(jSONObject.optBoolean("enable-early-return", false))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NUMBERFORMAT, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ASR_ENABLE_NUMBERFORMAT, true))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CITY_ID, BDSParamBase.intParam(jSONObject.optInt("cid"))); optInt = jSONObject.optInt("decoder-server.tts", jSONObject.optInt(Analysis.Item.TYPE_TTS, -1)); if (optInt != -1) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_PARAM, BDSParamBase.objectParam(jSONObject.optString(SpeechConstant.PAM, ""), "java.lang.String")); this.mEnableChunk = 1 != jSONObject.optInt(SpeechConstant.DEC_TYPE, jSONObject.optInt("basic.dec-type", 1)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_CHUNK_ENABLE, BDSParamBase.boolParam(this.mEnableChunk)); boolean equals222 = jSONObject.optString(SpeechConstant.NLU, "disable").equals("enable"); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_NLU, BDSParamBase.boolParam(equals222)); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-server.ptc", !equals222 ? 305 : 1))); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_KWS_PROTOCOL, BDSParamBase.intParam(jSONObject.optInt("decoder-offline.ptc", 0))); this.enableLongSpeech = jSONObject.optInt(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 1000) != 0; bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_LONG_SPEECH, BDSParamBase.boolParam(this.enableLongSpeech)); optBoolean = jSONObject.optBoolean("long-speech.multi-start-end", false); if (optBoolean) { } bDSMessage.m_messageParams.put(ASR_PARAM_KEY_ENABLE_HTTPDNS, BDSParamBase.boolParam(jSONObject.optBoolean(SpeechConstant.ENABLE_HTTPDNS, true))); optString3 = jSONObject.optString("keyword"); bDSMessage.m_messageParams.put(BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD, BDSParamBase.objectParam(optString3, "java.lang.String")); String optString14222 = jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH); String optString15222 = jSONObject.optString("decoder-offline.asr-base-file-path", jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_DAT_FILE_PATH, jSONObject.optString("kws.res-file", jSONObject.optString("res-file", format)))); String optString16222 = jSONObject.optString("decoder-offline.license-file-path", jSONObject.optString("license-file-path", jSONObject.optString("license"))); String optString17222 = jSONObject.optString("decoder-offline.slot-data", jSONObject.optString(SpeechConstant.SLOT_DATA)); if (TextUtils.isEmpty(optString14222)) { } if (optInt3 != 0) { } if (SpeechConstant.PUBLIC_DECODER) { } this.mOutFile = jSONObject.optString("audio.outfile", jSONObject.optString(SpeechConstant.OUT_FILE)); this.mEnableLogFeedBack = jSONObject.optBoolean("feedback-log", false); this.mFeedBackAudio = jSONObject.optBoolean(SpeechConstant.ACCEPT_AUDIO_DATA, false); if (this.mFeedBackAudio) { } try { postMessage = this.m_ASRcore.postMessage(bDSMessage); if (postMessage != 0) { } } catch (Throwable th) { th.printStackTrace(); BDSErrorDescription bDSErrorDescription3 = new BDSErrorDescription(); bDSErrorDescription3.errorCode = -2; bDSErrorDescription3.errorDomain = 1; bDSErrorDescription3.errorDescription = "JNI: initConfig Call to Native layer returned error! err"; return bDSErrorDescription3; } } private void initGrammer(String str) throws Exception { JSONObject jSONObject = new JSONObject(str); String optString = jSONObject.optString(SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH); if (!TextUtils.isEmpty(optString)) { final JSONObject jSONObject2 = this.mOriginNlp.get(optString); if (jSONObject2 == null) { try { jSONObject2 = this.mEventContext.loadJsonFromUri(optString, false, true); } catch (Exception unused) { Log.i(TAG, "bad grammar(as base64): " + optString); } } if (jSONObject2 == null) { try { jSONObject2 = this.mEventContext.loadJsonFromUri(optString, false, false); } catch (Exception unused2) { Log.i(TAG, "bad grammar(as text): " + optString); } } if (jSONObject2 != null && this.mOriginNlp.get(optString) == null) { this.mOriginNlp.put(optString, jSONObject2); } if (jSONObject2 != null) { final JSONObject optJSONObject = jSONObject.optJSONObject(SpeechConstant.SLOT_DATA); if (optJSONObject == null) { String optString2 = jSONObject.optString(SpeechConstant.SLOT_DATA); if (!TextUtils.isEmpty(optString2)) { optJSONObject = new JSONObject(optString2); } } this.nlpFeature = this.nluBuilderThread.submit(new Callable<JSONObject>() { /* class com.baidu.speech.core.ASREngine.AnonymousClass1 */ @Override // java.util.concurrent.Callable public JSONObject call() throws Exception { ASREngine.resetNlpGrammar(ASREngine.this.mEventContext, jSONObject2, optJSONObject); return jSONObject2; } }); } } } private boolean isIllegalResult(String str) { return str != null && str.contains("1。00。"); } private void loadGrammar(String str) { boolean z = false; try { JSONObject jSONObject = new JSONObject(str); if ("enable".equals(jSONObject.optString(SpeechConstant.NLU)) || "enable-all".equals(jSONObject.optString(SpeechConstant.NLU))) { z = true; } } catch (Exception e) { e.printStackTrace(); } if (z) { try { initGrammer(str); } catch (Exception e2) { e2.printStackTrace(); } } } /* JADX WARNING: Removed duplicated region for block: B:64:0x00fd A[SYNTHETIC, Splitter:B:64:0x00fd] */ /* JADX WARNING: Removed duplicated region for block: B:69:0x0107 A[SYNTHETIC, Splitter:B:69:0x0107] */ /* JADX WARNING: Removed duplicated region for block: B:77:0x0114 A[SYNTHETIC, Splitter:B:77:0x0114] */ /* JADX WARNING: Removed duplicated region for block: B:82:0x011e A[SYNTHETIC, Splitter:B:82:0x011e] */ private String loadSourceFromUri(String str) { Throwable th; RandomAccessFile randomAccessFile; InputStream inputStream; Exception e; InputStream inputStream2 = 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(ContentManifest.JsonKeys.FILE_PATH)) { inputStream = new FileInputStream(group2); } else { if (!group.equalsIgnoreCase("asset")) { if (!group.equalsIgnoreCase("assets")) { inputStream = group.equalsIgnoreCase("res") ? getClass().getResourceAsStream(group2) : null; } } String str2 = group2.startsWith("/") ? "" : "/"; inputStream = getClass().getResourceAsStream("/assets" + str2 + group2); } if (inputStream != null) { try { byte[] bArr = new byte[1024]; File file = new File(this.mContext.getFilesDir().getAbsolutePath() + group2); RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "rw"); while (true) { try { int read = inputStream.read(bArr); if (read <= 0) { break; } randomAccessFile2.write(bArr, 0, read); } catch (Exception e2) { randomAccessFile = randomAccessFile2; e = e2; try { e.printStackTrace(); if (inputStream != null) { } if (randomAccessFile != null) { } return null; } catch (Throwable th2) { th = th2; inputStream2 = inputStream; if (inputStream2 != null) { try { inputStream2.close(); } catch (Exception e3) { e3.printStackTrace(); } } if (randomAccessFile != null) { try { randomAccessFile.close(); } catch (IOException e4) { e4.printStackTrace(); } } throw th; } } catch (Throwable th3) { randomAccessFile = randomAccessFile2; th = th3; inputStream2 = inputStream; if (inputStream2 != null) { } if (randomAccessFile != null) { } throw th; } } String absolutePath = file.getAbsolutePath(); if (inputStream != null) { try { inputStream.close(); } catch (Exception e5) { e5.printStackTrace(); } } try { randomAccessFile2.close(); } catch (IOException e6) { e6.printStackTrace(); } return absolutePath; } catch (Exception e7) { e = e7; randomAccessFile = null; e.printStackTrace(); if (inputStream != null) { } if (randomAccessFile != null) { } return null; } catch (Throwable th4) { th = th4; randomAccessFile = null; inputStream2 = inputStream; if (inputStream2 != null) { } if (randomAccessFile != null) { } throw th; } } else { throw new IOException("bad data source"); } } } catch (Exception e8) { e = e8; inputStream = null; randomAccessFile = null; e.printStackTrace(); if (inputStream != null) { try { inputStream.close(); } catch (Exception e9) { e9.printStackTrace(); } } if (randomAccessFile != null) { try { randomAccessFile.close(); } catch (IOException e10) { e10.printStackTrace(); } } return null; } catch (Throwable th5) { th = th5; randomAccessFile = null; if (inputStream2 != null) { } if (randomAccessFile != null) { } throw th; } return null; } private int parseDecoder(String str) { try { JSONObject jSONObject = new JSONObject(str); return jSONObject.optInt("basic.decoder", jSONObject.optInt(SpeechConstant.DECODER)); } catch (Exception e) { e.printStackTrace(); return 0; } } private void play(Context context, Object obj, boolean z) { MediaPlayer mediaPlayer; Integer num; if (obj != null) { if (!(obj instanceof Integer) || ((num = (Integer) obj) != null && num.intValue() > 0)) { try { String str = "" + obj; if (str.matches("^(0x)?\\d+$")) { player.reset(); AssetFileDescriptor openRawResourceFd = context.getResources().openRawResourceFd(Integer.parseInt(str)); player.setDataSource(openRawResourceFd.getFileDescriptor(), openRawResourceFd.getStartOffset(), openRawResourceFd.getLength()); openRawResourceFd.close(); if (this.mStreamType >= 0) { player.setAudioStreamType(this.mStreamType); } mediaPlayer = player; } else { player.reset(); player.setDataSource(context, Uri.parse(str)); if (this.mStreamType >= 0) { player.setAudioStreamType(this.mStreamType); } mediaPlayer = player; } mediaPlayer.prepare(); player.start(); if (z) { while (player.isPlaying()) { try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); return; } } } } catch (Exception e2) { e2.printStackTrace(); } } } } private BDSErrorDescription postEvent(BDSErrorDescription bDSErrorDescription, String str) { BDSMessage bDSMessage = new BDSMessage(); bDSMessage.m_messageName = str; bDSMessage.m_messageParams = new HashMap<>(); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_PLATFORM, BDSParamBase.objectParam(this.mPlatform, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_SDK_VERSION, BDSParamBase.objectParam(this.mVersion, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_APP, BDSParamBase.objectParam(this.mApp, "java.lang.String")); bDSMessage.m_messageParams.put(ASR_PARAM_KEY_NETWORK_STATUS, BDSParamBase.intParam(Utility.getWifiOr2gOr3G(this.mContext))); if ((str.equals(ASR_CMD_START) || str.equals(ASR_CMD_STOP) || str.equals(ASR_CMD_CANCEL)) && this.mUserData != null) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_REALTIME_DATA, BDSParamBase.objectParam(this.mUserData, "java.lang.String")); this.mUserData = null; } if (str.equals(ASR_CMD_CONFIG)) { bDSMessage.m_messageParams.put(ASR_PARAM_KEY_VAD_ENABLE_LONG_PRESS, BDSParamBase.boolParam(this.mEnableLongPress)); } LogUtil.v(TAG, " cmd:" + str + " msg:" + bDSMessage.toString()); try { int postMessage = this.m_ASRcore.postMessage(bDSMessage); if (postMessage != 0) { BDSErrorDescription bDSErrorDescription2 = new BDSErrorDescription(); bDSErrorDescription2.errorCode = -2; bDSErrorDescription2.errorDomain = 1; bDSErrorDescription2.errorDescription = "JNI: readyParamsAsrStart Call to Native layer returned error! err( " + postMessage + " )"; return bDSErrorDescription2; } if (str.equals(ASR_CMD_START)) { this.mIsWorking = true; } if (str.equals(ASR_CMD_CANCEL)) { this.mIsWorking = false; } return bDSErrorDescription; } catch (Throwable th) { th.printStackTrace(); BDSErrorDescription bDSErrorDescription3 = new BDSErrorDescription(); bDSErrorDescription3.errorCode = -2; bDSErrorDescription3.errorDomain = 1; bDSErrorDescription3.errorDescription = "JNI: readyParamsAsrStart Call to Native layer returned error! err"; return bDSErrorDescription3; } } /* access modifiers changed from: private */ public static void resetNlpGrammar(EventContext eventContext, JSONObject jSONObject, JSONObject jSONObject2) throws JSONException { System.currentTimeMillis(); if (jSONObject2 != null) { JSONObject jSONObject3 = jSONObject.getJSONObject("slots"); Iterator<String> keys = jSONObject2.keys(); while (keys.hasNext()) { String next = keys.next(); jSONObject3.put(next, jSONObject2.getJSONArray(next)); } } HashMap hashMap = new HashMap(); JSONObject jSONObject4 = jSONObject.getJSONObject("slots"); Iterator<String> keys2 = jSONObject4.keys(); while (keys2.hasNext()) { String next2 = keys2.next(); JSONArray jSONArray = jSONObject4.getJSONArray(next2); ArrayList arrayList = new ArrayList(); for (int i = 0; i < jSONArray.length(); i++) { String string = jSONArray.getString(i); if (!string.equals(".+")) { string = string.replaceAll("[\u0000-/]|[:-@]|[\\[-`]|[{-]", ""); } arrayList.add(string); } String join = eventContext.join(arrayList, "|"); hashMap.put(String.format("<%s>", next2), String.format("(%s)", join)); } JSONObject jSONObject5 = jSONObject.getJSONObject("rules"); Iterator<String> keys3 = jSONObject5.keys(); while (keys3.hasNext()) { JSONArray jSONArray2 = jSONObject5.getJSONArray(keys3.next()); for (int i2 = 0; i2 < jSONArray2.length(); i2++) { JSONObject jSONObject6 = jSONArray2.getJSONObject(i2); String string2 = jSONObject6.getString("origin"); for (Map.Entry entry : hashMap.entrySet()) { string2 = string2.replaceAll((String) entry.getKey(), (String) entry.getValue()); } jSONObject6.put("pattern", "^" + string2 + "$"); } } } /* JADX WARNING: Removed duplicated region for block: B:23:0x0031 */ /* JADX WARNING: Removed duplicated region for block: B:25:0x0037 A[SYNTHETIC, Splitter:B:25:0x0037] */ /* JADX WARNING: Removed duplicated region for block: B:34:? A[RETURN, SYNTHETIC] */ private void saveOutFile(byte[] bArr) { Throwable th; IOException e; String str = this.mOutFile; if (str != null && !str.equals("") && bArr != null) { FileOutputStream fileOutputStream = null; try { FileOutputStream fileOutputStream2 = new FileOutputStream(this.mOutFile, 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; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e4) { e4.printStackTrace(); } } throw th; } } catch (Throwable th3) { th = th3; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { } throw th; } } catch (IOException e5) { e = e5; e.printStackTrace(); if (fileOutputStream == null) { fileOutputStream.close(); } } } } private void updateUserData(String str) { if (str != null) { try { if (!str.equals("")) { this.mUserData = new JSONObject(str).optString("realtime-data"); return; } } catch (Exception e) { e.printStackTrace(); this.mUserData = null; return; } } this.mUserData = null; } /* JADX WARNING: Removed duplicated region for block: B:94:0x0220 */ public BDSErrorDescription postEvent(String str, String str2) { JSONObject jSONObject; LogUtil.v(TAG, " postEvent params: cmd:" + str + " params:" + str2); if (str == null || str.equals("")) { BDSErrorDescription bDSErrorDescription = new BDSErrorDescription(); bDSErrorDescription.errorCode = -1; bDSErrorDescription.errorDomain = 1; bDSErrorDescription.errorDescription = "ASR param can not empty!"; return bDSErrorDescription; } BDSErrorDescription bDSErrorDescription2 = null; if (str.equals(ASR_CMD_START)) { if (this.mIsWorking) { try { this.mListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, generateErrorResult(AsrError.ERROR_ASR_ENGINE_BUSY, null), null, 0, 0); return null; } catch (Exception unused) { } } if (parseDecoder(str2) == 0 && Utility.getWifiOr2gOr3G(this.mContext) == 0) { try { play(this.mContext, Integer.valueOf(new JSONObject(str2).optInt(SpeechConstant.SOUND_ERROR, -1)), false); this.mListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, generateErrorResult(AsrError.ERROR_NETWORK_NOT_AVAILABLE, null), null, 0, 0); this.mListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_EXIT, generateErrorResult(AsrError.ERROR_NETWORK_NOT_AVAILABLE, null), null, 0, 0); this.mIsWorking = false; return null; } catch (Exception unused2) { } } if (!Utility.checkPermission(this.mContext, "android.permission.INTERNET")) { try { play(this.mContext, Integer.valueOf(new JSONObject(str2).optInt(SpeechConstant.SOUND_ERROR, -1)), false); this.mListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, generateErrorResult(AsrError.ERROR_NETWORK_NOT_GRANTED, null), null, 0, 0); this.mListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_EXIT, generateErrorResult(AsrError.ERROR_NETWORK_NOT_GRANTED, null), null, 0, 0); this.mIsWorking = false; return null; } catch (Exception e) { e.printStackTrace(); } } if (!Utility.checkPermission(this.mContext, "android.permission.RECORD_AUDIO")) { try { play(this.mContext, Integer.valueOf(new JSONObject(str2).optInt(SpeechConstant.SOUND_ERROR, -1)), false); this.mListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, generateErrorResult(AsrError.ERROR_NO_RECORD_PERMISSION, null), null, 0, 0); this.mListener.onEvent(SpeechConstant.CALLBACK_EVENT_ASR_EXIT, generateErrorResult(AsrError.ERROR_NO_RECORD_PERMISSION, null), null, 0, 0); this.mIsWorking = false; return null; } catch (Exception e2) { e2.printStackTrace(); } } loadGrammar(str2); } if (str.equals(ASR_CMD_START)) { this.mCalledStop = false; } if (str.equals(ASR_CMD_STOP)) { updateUserData(str2); this.mCalledStop = true; } if (str.equals(ASR_CMD_START) || str.equals(ASR_CMD_STOP) || str.equals(ASR_CMD_CANCEL)) { updateUserData(str2); } if (str.equals(ASR_CMD_START) || str.equals(ASR_CMD_LOAD_ENGINE)) { try { this.mParams = new JSONObject(str2); } catch (Exception unused3) { this.mParams = new JSONObject(); } if (str.equals(ASR_CMD_START)) { play(this.mContext, Integer.valueOf(this.mParams.optInt(SpeechConstant.SOUND_START, -1)), this.mParams.optBoolean("audio.sound-sync", true)); try { if (!this.mParams.has("audio.socketport")) { this.mParams.put("audio.socketport", MicrophoneServer.create(this.mParams.optString(SpeechConstant.IN_FILE), this.mParams.has(SpeechConstant.AUDIO_SOURCE) ? this.mParams.optInt(SpeechConstant.AUDIO_SOURCE) : 1)); } } catch (Exception e3) { e3.printStackTrace(); } } else { loadGrammar(str2); } try { bDSErrorDescription2 = initConfig(null, this.mParams); if (str.equals(ASR_CMD_START)) { clearOutFile(); } if (this.mExceptioned) { return bDSErrorDescription2; } } catch (Exception unused4) { } if (bDSErrorDescription2 != null) { return bDSErrorDescription2; } } if (str.equals(ASR_CMD_CONFIG)) { if (str2 != null) { try { if (!str2.equals("")) { jSONObject = new JSONObject(str2); if (jSONObject.has("vad_enable_long_press.bool")) { this.mEnableLongPress = jSONObject.optBoolean("vad_enable_long_press.bool", true); } } } catch (Exception e4) { e4.printStackTrace(); jSONObject = new JSONObject(); } } jSONObject = new JSONObject(); if (jSONObject.has("vad_enable_long_press.bool")) { } } return postEvent(bDSErrorDescription2, str); } @Override // com.baidu.speech.core.BDSSDKLoader.BDSCoreEventListener public void receiveCoreEvent(BDSMessage bDSMessage, BDSSDKLoader.BDSSDKInterface bDSSDKInterface) { ASRListener aSRListener = this.mListener; if (aSRListener != null && bDSMessage != null) { asrCallBack(bDSMessage, aSRListener); } } public void setListener(ASRListener aSRListener) { this.mListener = aSRListener; } }