欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

百度语音唤醒踩坑合集

程序员文章站 2022-03-28 16:11:59
一、在语音识别中可以正常运行,唤醒也可以用,但是当判断是什么唤醒词语的时候出错?Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.W/System.err: org.json.JSONException: No value for appidat ....

一、在语音识别中可以正常运行,唤醒也可以用,但是当判断是什么唤醒词语的时候出错?

Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/System.err: org.json.JSONException: No value for appid
at org.json.JSONObject.get(JSONObject.java:399)
at org.json.JSONObject.getInt(JSONObject.java:488)
at com.baidu.speech.asr.AnalysisInterceptor.send(Unknown Source:87)
at com.baidu.speech.asr.EventManagerWp.send(Unknown Source:47)
at vip.mtmy.helloworld.MainActivity.start(MainActivity.java:98)
at vip.mtmy.helloworld.MainActivity$1.onClick(MainActivity.java:58)
W/System.err: at android.view.View.performClick(View.java:7125)
W/System.err: at android.view.View.performClickInternal(View.java:7102)
W/System.err: at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
W/System.err: at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/MicrophoneServer: infile: audioSource:1
I/[BDASR_LOG] MicrophoneServer: add wrap socket, mRemoteOutputStreams size = 1 firstStart = true
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: vip.mtmy.helloworld, PID: 7280
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:121)
at org.json.JSONTokener.nextValue(JSONTokener.java:98)
at org.json.JSONObject.<init>(JSONObject.java:164)
at org.json.JSONObject.<init>(JSONObject.java:181)
at vip.mtmy.helloworld.MainActivity.onEvent(MainActivity.java:109)
at com.baidu.speech.asr.EventManagerWp$2$1.run(Unknown Source:56)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/[BDASR_LOG] audioSource :: 1
I/[BDASR_LOG] MicInputStream: startRecordingAndCheckStatus recorder status is 1
I/Process: Sending signal. PID: 7280 SIG: 9

解决方式:JSONObject jsonObject=new JSONObject(params);String word=jsonObject.getString(“word”);放到判断语句中即可解决

public void onEvent(String name, String params, byte[] data, int offset, int length) {
        txtResult.setText(name);
        try {
            if ("wp.data".equals(name)) {
                JSONObject jsonObject=new JSONObject(params);
                String word=jsonObject.getString("word");
                if (word.equals("陌途陌影")){
                    Toast.makeText(this, "唤醒成功啊", Toast.LENGTH_LONG).show();
                }
                // 识别相关的结果都在这里
                Log.d("唤醒","唤醒成功");
            }
            else{
                Toast.makeText(this,"唤醒失败",Toast.LENGTH_LONG).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

本文地址:https://blog.csdn.net/qq_43691312/article/details/107590012

相关标签: android 踩坑