|
|
|
@ -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() { |
|
|
|
|