|
|
|
@ -43,6 +43,7 @@ import com.aispeech.export.config.AILocalSignalAndWakeupConfig; |
|
|
|
import com.aispeech.export.engines2.AICloudASREngine; |
|
|
|
import com.aispeech.export.engines2.AILocalSignalAndWakeupEngine; |
|
|
|
import com.aispeech.export.intent.AICloudASRIntent; |
|
|
|
import com.aispeech.export.intent.AILocalSignalAndWakeupIntent; |
|
|
|
import com.aispeech.export.listeners.AIASRListener; |
|
|
|
import com.aispeech.export.listeners.AILocalSignalAndWakeupListener; |
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route; |
|
|
|
@ -51,6 +52,7 @@ import com.alibaba.android.arouter.launcher.ARouter; |
|
|
|
import org.greenrobot.eventbus.EventBus; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Map; |
|
|
|
@ -86,16 +88,15 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
static final int TYPE_GO_SAVESCREEN = 300;//导视通知跳转屏保
|
|
|
|
static final int TYPE_HINT_PASSWORD = 3;//隐藏密码输入框
|
|
|
|
static final int TYPE_START_SERVER = 4;//重新启动web服务
|
|
|
|
//static String HtmlUrl = "http://127.0.0.1:8080/index.html";//webServer服务地址 http://192.168.1.218:5173/
|
|
|
|
static String HtmlUrl = "http://192.168.1.196:5173/"; //"http://192.168.0.109:5173/";
|
|
|
|
static String HtmlUrl = "http://127.0.0.1:8080/index.html";//webServer服务地址 http://192.168.1.218:5173/
|
|
|
|
//static String HtmlUrl = "http://192.168.1.196:5173/"; //"http://192.168.0.109:5173/";
|
|
|
|
int time = 0; |
|
|
|
private VideoView currentVideo; |
|
|
|
private SoundPool soundPool; |
|
|
|
private int soundId; |
|
|
|
// 语音听写对象
|
|
|
|
private AILocalSignalAndWakeupEngine mLocalEngine; |
|
|
|
private AICloudASREngine mEngine; |
|
|
|
private AICloudASRIntent aiCloudASRIntent; |
|
|
|
private AILocalSignalAndWakeupEngine mEngine; |
|
|
|
private AICloudASREngine mAsrEngine; |
|
|
|
private TTSUtil ttsUtil; |
|
|
|
private String oldString=""; |
|
|
|
private Map<String, Uri> videoMap = new HashMap<>(); |
|
|
|
@ -832,12 +833,11 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
public void startRecord() { |
|
|
|
LoggerUtil.e(TAG,"JS调用了Android的方法:startRecord()"); |
|
|
|
ttsUtil.stopTTs(); |
|
|
|
stopAsr(); |
|
|
|
if(mEngine == null){ |
|
|
|
if(mAsrEngine == null){ |
|
|
|
LoggerUtil.d(TAG, "未初始化"); |
|
|
|
initASR(); |
|
|
|
} |
|
|
|
mEngine.start(aiCloudASRIntent); |
|
|
|
startEngine(); |
|
|
|
runOnUiThread(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
@ -933,34 +933,24 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
|
|
|
|
//--------
|
|
|
|
private void initASR(){ |
|
|
|
|
|
|
|
AILocalSignalAndWakeupConfig config = new AILocalSignalAndWakeupConfig(); |
|
|
|
config.setSspeResource("sspe_aec-bf-bss-wkp_ch10-mic8-ref2_outgain4_v2.0.0.165_20251127_v1.bin");//设置SSPE资源
|
|
|
|
config.setWakeupResource("wakeup_aifar_comm_h7_20210127.bin");//设置唤醒资源
|
|
|
|
config.setSspeResource("sspe_aec-bf-bss-wkp_ch10-mic8-ref2_outgain4_v2.0.0.165_20251127_v1.bin"); //设置SSPE资源
|
|
|
|
|
|
|
|
config.setWakeupWord(new String[]{"ni hao xiao le"}, new int[]{1}); |
|
|
|
config.setThreshold(new float[]{0.9f}); //设置唤醒词对应的阈值
|
|
|
|
config.setEchoChannelNum(2); |
|
|
|
mLocalEngine = AILocalSignalAndWakeupEngine.createInstance(); |
|
|
|
mLocalEngine.init(config, new SSPEListener()); |
|
|
|
|
|
|
|
if(mEngine == null){ |
|
|
|
AICloudASRConfig asrconfig = new AICloudASRConfig(); |
|
|
|
asrconfig.setLocalVadEnable(true); |
|
|
|
asrconfig.setVadResource("vad_aihome_v0.12c_noDither.bin"); |
|
|
|
mEngine = AICloudASREngine.createInstance(); |
|
|
|
mEngine.init(asrconfig, new AIASRListenerImpl()); |
|
|
|
|
|
|
|
aiCloudASRIntent = new AICloudASRIntent(); |
|
|
|
aiCloudASRIntent.setEnablePunctuation(true); |
|
|
|
aiCloudASRIntent.setRealback(true);//打开实时反馈功能
|
|
|
|
aiCloudASRIntent.setCloudVadEnable(false); |
|
|
|
aiCloudASRIntent.setAudioType(AICloudASRIntent.PCM_ENCODE_TYPE.valueOf("WAV")); |
|
|
|
aiCloudASRIntent.setResourceType(Constant.asrModel); |
|
|
|
aiCloudASRIntent.setEnableNumberConvert(true);//设置启用识别结果汉字数字转阿拉伯数字功能
|
|
|
|
aiCloudASRIntent.setWaitingTimeout(10000); //设置等待识别结果超时时长,默认5000ms
|
|
|
|
aiCloudASRIntent.setNoSpeechTimeOut(5000); |
|
|
|
aiCloudASRIntent.setPauseTime(3000); |
|
|
|
//aiCloudASRIntent.setUseCustomFeed(false); // 设置是否使用外部喂音频
|
|
|
|
} |
|
|
|
config.enableDulWakeupWithE2E(new String[]{"ni hao xiao le"}, new String[]{}, new float[]{0.9f}, new float[]{0.1f}); |
|
|
|
mEngine = AILocalSignalAndWakeupEngine.createInstance(); |
|
|
|
mEngine.init(config, new SSPEListener()); |
|
|
|
|
|
|
|
mAsrEngine = AICloudASREngine.createInstance(); |
|
|
|
AICloudASRConfig asrconfig = new AICloudASRConfig(); |
|
|
|
asrconfig.setLocalVadEnable(true); |
|
|
|
asrconfig.setVadResource("vad_aihome_v0.12c_noDither.bin"); |
|
|
|
mAsrEngine.init(asrconfig, new AIASRListenerImpl()); |
|
|
|
|
|
|
|
//initRecorder(); //暂不开
|
|
|
|
initRecorder(); |
|
|
|
} |
|
|
|
|
|
|
|
private void initRecorder() { |
|
|
|
@ -968,22 +958,37 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
IRecord.RecordConfig config = new IRecord.RecordConfig(); |
|
|
|
config.recorderType = IRecord.TYPE_JNI; |
|
|
|
config.audioChannel = 10; |
|
|
|
// config.filter = new int[]{0, 1, 2, 3, 6, 7};
|
|
|
|
config.dump = true; // 不保存外部录音机收到的音频
|
|
|
|
AudioRecorder.getInstance().init(getApplicationContext(), config); |
|
|
|
} |
|
|
|
|
|
|
|
public class RecorderListener implements AudioRecorder.RecorderListener { |
|
|
|
private void startEngine(){ |
|
|
|
AudioRecorder.getInstance().startRecord(); |
|
|
|
AILocalSignalAndWakeupIntent intent = new AILocalSignalAndWakeupIntent(); |
|
|
|
intent.setUseCustomFeed(true); |
|
|
|
intent.setInputContinuousAudio(true); |
|
|
|
mEngine.start(intent); |
|
|
|
AICloudASRIntent aiCloudASRIntent = new AICloudASRIntent(); |
|
|
|
aiCloudASRIntent.setRealback(true);//打开实时反馈功能
|
|
|
|
aiCloudASRIntent.setCloudVadEnable(false); |
|
|
|
aiCloudASRIntent.setAudioType(AICloudASRIntent.PCM_ENCODE_TYPE.WAV); |
|
|
|
aiCloudASRIntent.setResourceType(Constant.asrModel); |
|
|
|
aiCloudASRIntent.setEnableNumberConvert(true);//设置启用识别结果汉字数字转阿拉伯数字功能
|
|
|
|
aiCloudASRIntent.setWaitingTimeout(10000); //设置等待识别结果超时时长,默认5000ms
|
|
|
|
aiCloudASRIntent.setNoSpeechTimeOut(5000); |
|
|
|
aiCloudASRIntent.setPauseTime(3000); |
|
|
|
aiCloudASRIntent.setUseCustomFeed(true); // 设置是否使用外部喂音频
|
|
|
|
//aiCloudASRIntent.setServer("wss://asr.dui.ai/runtime/v2/recognize");
|
|
|
|
mAsrEngine.start(aiCloudASRIntent); |
|
|
|
LoggerUtil.e("ASRInit", "start asr engine"); |
|
|
|
} |
|
|
|
|
|
|
|
public class RecorderListener implements AudioRecorder.RecorderListener { |
|
|
|
@Override |
|
|
|
public void onAudioBuffer(byte[] data, int size) { |
|
|
|
feedEngine(data, size); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected void feedEngine(byte[] data, int length) { |
|
|
|
if (mLocalEngine != null) { |
|
|
|
mLocalEngine.feedData(data, length); |
|
|
|
if (mEngine != null) { |
|
|
|
mEngine.feedData(data, size); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1002,9 +1007,13 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
} |
|
|
|
|
|
|
|
public void onResults(AIResult results) { |
|
|
|
LoggerUtil.e("ASRInitResult: ", String.valueOf(results.isLast())); |
|
|
|
LoggerUtil.e("ASRInitResult: ", String.valueOf(results)); |
|
|
|
|
|
|
|
if (results.getResultType() == AIConstant.AIENGINE_MESSAGE_TYPE_JSON) { |
|
|
|
JSONResultParser parser = new JSONResultParser((String) results.getResultObject()); |
|
|
|
if (parser.getEof() == 1) { |
|
|
|
LoggerUtil.e("ASRInitResult: ",parser.getText()); |
|
|
|
} |
|
|
|
if("".equals(parser.getVar()) && !"".equals(parser.getText())){ |
|
|
|
oldString = StringUtil.strSplice(oldString,parser.getText()); |
|
|
|
} |
|
|
|
@ -1126,8 +1135,8 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onResultDataReceived(byte[] bytes, int size, int wakeupType) { |
|
|
|
if (mEngine != null) { |
|
|
|
mEngine.feedData(bytes, size); |
|
|
|
if (mAsrEngine != null) { |
|
|
|
mAsrEngine.feedData(bytes, size); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1190,9 +1199,13 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
} |
|
|
|
private void stopAsr(){ |
|
|
|
if(mEngine != null){ |
|
|
|
mEngine.cancel(); |
|
|
|
mEngine.stop(); |
|
|
|
} |
|
|
|
if(mAsrEngine != null){ |
|
|
|
mAsrEngine.cancel(); |
|
|
|
mAsrEngine.stop(); |
|
|
|
} |
|
|
|
AudioRecorder.getInstance().stopRecord(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|