diff --git a/app/build.gradle b/app/build.gradle index e5f50b2..b2ffb40 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { minSdkVersion 22 targetSdkVersion 30 versionCode 6 - versionName "V2.0.7.33" + versionName "V2.0.7.34" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles 'consumer-rules.pro' diff --git a/app/src/main/java/qianmu/container/activity/H5/WebViewActivity.java b/app/src/main/java/qianmu/container/activity/H5/WebViewActivity.java index 45217ae..a93f43f 100644 --- a/app/src/main/java/qianmu/container/activity/H5/WebViewActivity.java +++ b/app/src/main/java/qianmu/container/activity/H5/WebViewActivity.java @@ -483,26 +483,30 @@ public class WebViewActivity extends BaseActivity { @JavascriptInterface public void startRecord() { LoggerUtil.e(TAG,"JS调用了Android的方法:startRecord()"); - if("sbc".equals(Constant.TTSFac)) { - if (localSocketClient == null) initLocalSocketClient(); //------------------------------- - localSocketClient.send(StringUtil.strSplice("{\"method\":\"/tts/stop\"}")); - localSocketClient.send(StringUtil.strSplice("{\"method\":\"/asr/start\"}")); - }else{ - if(isrun){ - return; - } - ttsUtil.stopTTs(); - if(mAsr == null){ - LoggerUtil.d(TAG, "未初始化"); - initASR(); - } - count++; - int ret = mAsr.startListener(count+""); - if(ret != 0){ - LoggerUtil.d(TAG,"识别开启失败,错误码:"+ret+"\n"); + try{ + if("sbc".equals(Constant.TTSFac)) { + if (localSocketClient == null) initLocalSocketClient(); //------------------------------- + localSocketClient.send(StringUtil.strSplice("{\"method\":\"/tts/stop\"}")); + localSocketClient.send(StringUtil.strSplice("{\"method\":\"/asr/start\"}")); }else{ - isrun = true; + if(isrun){ + return; + } + ttsUtil.stopTTs(); + if(mAsr == null){ + LoggerUtil.d(TAG, "未初始化"); + initASR(); + } + count++; + int ret = mAsr.startListener(count+""); + if(ret != 0){ + LoggerUtil.d(TAG,"识别开启失败,错误码:"+ret+"\n"); + }else{ + isrun = true; + } } + }catch (Exception e){ + LoggerUtil.e(TAG,e.getMessage()); } runOnUiThread(new Runnable() { @Override @@ -515,34 +519,48 @@ public class WebViewActivity extends BaseActivity { @JavascriptInterface public void stopRecord() { LoggerUtil.e(TAG,"JS调用了Android的方法:stopRecord()"); - if("sbc".equals(Constant.TTSFac)) { - if (localSocketClient == null) initLocalSocketClient(); //------------------------------- - localSocketClient.send(StringUtil.strSplice("{\"method\":\"/asr/stop\"}")); - }else{ - stopAsr(); + try{ + if("sbc".equals(Constant.TTSFac)) { + if (localSocketClient == null) initLocalSocketClient(); //------------------------------- + localSocketClient.send(StringUtil.strSplice("{\"method\":\"/asr/stop\"}")); + }else{ + stopAsr(); + } + }catch (Exception e){ + LoggerUtil.e(TAG,e.getMessage()); } + } // h5调用android:开始合成语音 @JavascriptInterface public void startTTS(String txt) { LoggerUtil.e(TAG,"JS调用了Android的方法:startTTS()"); - if("sbc".equals(Constant.TTSFac)) { - if (localSocketClient == null) initLocalSocketClient(); //------------------------------- - localSocketClient.send(StringUtil.strSplice("{\"method\": \"/tts/start\",\"params\": {\"text\":\"", txt, "\", \"mode\":\"autoPlay\"}}")); - }else{ - ttsUtil.startTTs(txt); + try{ + if("sbc".equals(Constant.TTSFac)) { + if (localSocketClient == null) initLocalSocketClient(); //------------------------------- + localSocketClient.send(StringUtil.strSplice("{\"method\": \"/tts/start\",\"params\": {\"text\":\"", txt, "\", \"mode\":\"autoPlay\"}}")); + }else{ + ttsUtil.startTTs(txt); + } + }catch (Exception e){ + LoggerUtil.e(TAG,e.getMessage()); } } // h5调用android:停止合成语音 @JavascriptInterface public void stopTTS() { LoggerUtil.e(TAG,"JS调用了Android的方法:stopTTS()"); - if("sbc".equals(Constant.TTSFac)){ - if (localSocketClient == null) initLocalSocketClient(); //------------------------------- - localSocketClient.send(StringUtil.strSplice("{\"method\":\"/tts/stop\"}")); - }else{ - ttsUtil.stopTTs(); + try{ + if("sbc".equals(Constant.TTSFac)){ + if (localSocketClient == null) initLocalSocketClient(); //------------------------------- + localSocketClient.send(StringUtil.strSplice("{\"method\":\"/tts/stop\"}")); + }else{ + ttsUtil.stopTTs(); + } + }catch (Exception e){ + LoggerUtil.e(TAG,e.getMessage()); } + runOnUiThread(new Runnable() { @Override public void run() {