今天在在使用语音识别功能的时候编辑的代码很正常:编译也通过了,但是在点击录音按钮的时候报了一个令人费解的错误:Broken pipe,查阅了很多帖子也没有解决,请大佬们答疑
错误日志:
/ASREngine: EVoiceRecognitionClientWorkStatusError errorDomain : 33 errorCode : -3004 desc : Server app name unknown.[(-3004)4: Open api request limit reached] mLastRecognitionResult:
D/ASREngine: generateErrorResult errDomain = 33 errCode = -3004
W/System.err: java.lang.NullPointerException: Attempt to write to field 'int com.baidu.speech.utils.analysis.Analysis$Item.error_code' on a null object reference
at com.baidu.speech.asr.AnalysisInterceptor.onEvent(Unknown Source:61)
at com.baidu.speech.asr.EventManagerAsr.onEvent(Unknown Source:12)
at com.baidu.speech.asr.EventManagerAsr.onEvent(Unknown Source:7)
at com.baidu.speech.core.ASREngine.asrCallBack(Unknown Source:581)
at com.baidu.speech.core.ASREngine.receiveCoreEvent(Unknown Source:6)
at com.baidu.speech.core.BDSCoreJniInterface.receiveCoreEvent(Unknown Source:18)
V/ASREngine: ASRCallBack :18
W/System.err: java.lang.NullPointerException: Attempt to read from field 'int com.baidu.speech.utils.analysis.Analysis$Item.appId' on a null object reference
at com.baidu.speech.utils.analysis.Analysis.log(Unknown Source:20)
at com.baidu.speech.asr.AnalysisInterceptor.onEvent(Unknown Source:75)
at com.baidu.speech.asr.EventManagerAsr.onEvent(Unknown Source:12)
at com.baidu.speech.asr.EventManagerAsr.onEvent(Unknown Source:7)
at com.baidu.speech.core.ASREngine.asrCallBack(Unknown Source:128)
at com.baidu.speech.core.ASREngine.receiveCoreEvent(Unknown Source:6)
at com.baidu.speech.core.BDSCoreJniInterface.receiveCoreEvent(Unknown Source:18)
W/System.err: java.util.concurrent.ExecutionException: java.io.IOException: Broken pipe
at java.util.concurrent.FutureTask.report(FutureTask.java:123)
at java.util.concurrent.FutureTask.get(FutureTask.java:207)
at com.baidu.speech.audio.MicrophoneServer.run(Unknown Source:90)
at java.lang.Thread.run(Thread.java:929)
W/System.err: Caused by: java.io.IOException: Broken pipe
at android.net.LocalSocketImpl.writeba_native(Native Method)
at android.net.LocalSocketImpl.access$500(LocalSocketImpl.java:37)
at android.net.LocalSocketImpl$SocketOutputStream.write(LocalSocketImpl.java:147)
at com.baidu.speech.audio.MicrophoneServer$2.call(Unknown Source:17)
at com.baidu.speech.audio.MicrophoneServer$2.call(Unknown Source:0)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
... 1 more
I/[BDASR_LOG] MicrophoneServer: finally, mRemoteOutputStreams size = 0 firstStart = true
I/AudioRecord: setBlueToothScoState() state:1, audiosource:1
I/HwAudioRecordImpl: sendStateChangedIntent, state=1
W/AudioSystem: (gLock) AudioSystem start get_audio_flinger()
(gLock) AudioSystem end get_audio_flinger()ms: 0ms
W/InputMethodManager: startInputReason = 8
E/RtgSchedManager: endActivityTransaction: margin state not match
E/RtgSchedManager: endActivityTransaction: margin state not match
E/RtgSchedManager: endActivityTransaction: margin state not match
W/libEGL: EGLNativeWindowType 0x7ef6629c10 disconnect failed
I/ActivityThread: Handle window ActivityRecord{18e89e2 token=android.os.BinderProxy@7c6d007 {com.njucm.meridian_and_acupoint_health_guard/com.njucm.meridian_and_acupoint_health_guard.MainActivity}} visibility: false
E/RtgSchedManager: endActivityTransaction: margin state not match
D/DecorView: showOrHideHighlightView: hasFocus=false; winMode=1; isMrgNull=true
D/RtgSched: resetRtgSchedHandle failed enable:0
D/ZrHung.AppEyeUiProbe: not watching, wait.
I/AwareBitmapCacher: handleReleaseCache: pid=31559
I/AwareBitmapCacher: init lrucache size: 2097152 pid=31559
主类代码:
private DashboardViewModel dashboardViewModel;
//识别
protected TextView txtResult;//识别结果
protected Button startBtn;//开始识别 一直不说话会自动停止,需要再次打开
protected Button stopBtn;//停止识别
private EventManager asr;//语音识别核心库
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
dashboardViewModel =
new ViewModelProvider(this).get(DashboardViewModel.class);
View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
initView(root);
//初始化EventManager对象
asr = EventManagerFactory.create(getContext(), "asr");
//注册自己的输出事件类
asr.registerListener(this); // EventListener 中 onEvent方法
return root;
}
@Override
public void onEvent(String name, String params, byte[] data, int offset, int length) {
if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL)) {
// 识别相关的结果都在这里
if (params == null || params.isEmpty()) {
return;
}
if (params.contains("\"final_result\"")) {
// 一句话的最终识别结果
txtResult.setText(params);
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
//发送取消事件
asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0);
//退出事件管理器
// 必须与registerListener成对出现,否则可能造成内存泄露
asr.unregisterListener(this);
}
private void initView(View root) {
txtResult = (TextView) root.findViewById(R.id.tv_txt);
startBtn = (Button) root.findViewById(R.id.btn_start);
stopBtn = (Button) root.findViewById(R.id.btn_stop);
startBtn.setOnClickListener(new View.OnClickListener() {//开始
@Override
public void onClick(View v) {
asr.send(SpeechConstant.ASR_START, null, null, 0, 0);
}
});
stopBtn.setOnClickListener(new View.OnClickListener() {//停止
@Override
public void onClick(View v) {
asr.send(SpeechConstant.ASR_STOP, null, null, 0, 0);
}
});
}
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
-3004 是鉴权问题,检查下鉴权。Broken pipe可以忽略