百度语音集成离线功能

一、申请key https://console.bce.baidu.com/ai/#/ai/speech/overview/index
最新版SDK(http://bos.nj.bpc.baidu.com/v1/audio/audiobd_speech_sdk_asr_v3.0.7.3_bdasr_20180313_726f26e.zip) 离线命令词只能识别”打电话给妈妈”
可以修改com.baidu.android.voicedemo.recognization.offline包下的文件
OfflineRecogParams.java文件中的如下方法,即可离线识别打电话给光头强,等

public static Map<String, Object> fetchSlotDataParam() {
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject json = new JSONObject();
            json.put("name", new JSONArray().put("妈妈").put("老伍").put("10086").put("1007").put("李明").put("光头强"))
                    .put("appname", new JSONArray().put("手百").put("度秘"));
            map.put(SpeechConstant.SLOT_DATA, json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return map;
    }

offline engine recognize fail
:解决,先在线正确识别后,关闭应用(最好这样做),断网,再次打开应用,离线识别
在fetchSlotDataParam方法中(见上面)配置你要识别的字段

offline engine not initial: 拷贝baidu_speech_grammar.bas文件到assets目录
recorder open failed:开始录音后,要结束录音。另外,如果你的设备(手机)上有两个百度识别的应用,一个百度sdkdemo,一个你自己的应用,在用sdk demo测试完后,最好清除内存(直接按返回键后,再打开另个一百度语音识别的的应用,容易报这个问题)。
download network read failed:没有联网,或者离现识别的appkey 等配置不正确

集成过程中出现的问题:jni异常,点击离线识别后,界面直接卡死,刚开始一直以为是so库冲突导致的,后台单一变量原则逐步分析,排查出是项目里面引入了一个framework.jar 包。去除此jar包后,正常,同时想到是context异常的问题,确认是此问题无疑问。

08-01 09:32:56.490 14342-14342/? I/MyRecognizer.Debug: loadOfflineEngine params:{"decoder":2,"grammar":"assets:\/\/\/baidu_speech_grammar.bsg","slot-data":{"name":["妈妈","老伍","10086","80001","李明","光头强"],"appname":["手百","度秘"]}}
08-01 09:32:56.490 14342-14342/? E/ASREngine: VAD Model=dnn
08-01 09:32:56.490 14342-14342/? I/[BDASR_LOG] Policy: use custom galaxy = false
08-01 09:32:56.510 3460-4035/? I/HwSystemManager: HoldService:callUid: 10312 notificationType: false
08-01 09:32:56.510 3460-4035/? I/HwSystemManager: HoldService:pkgName[0]: com.jiaxun.aruil identity: 4299262267217
08-01 09:32:56.510 3460-3484/? I/HwSystemManager: HoldService:checkBeforeShowDialog: uid:10312 pid:14342, permissionType:16
08-01 09:32:56.510 3460-3484/? I/HwSystemManager: OverseaCfgHelper:permissionStatus is 0
08-01 09:32:56.510 3460-3484/? I/HwSystemManager: ShareLib:pkgNameList:1
08-01 09:32:56.510 3460-3484/? I/HwSystemManager: ShareLib:getApplication pkgName:com.jiaxun.aruil
08-01 09:32:56.510 3460-3484/? I/HwSystemManager: ShareLib:getAppInfo the final pkgName:com.jiaxun.aruil
08-01 09:32:56.520 3460-3484/? I/CachedDir: dir=/data/skin(3460,-1414976216)
08-01 09:32:56.520 3460-3484/? I/CachedDir: dir=/data/skin_ps(3460,-1414976216)
08-01 09:32:56.520 3460-3484/? I/HwSystemManager: ShareLib:getAppInfo time consume:5
08-01 09:32:56.520 3460-3484/? I/HwSystemManager: ShareLib:getAppInfoByUidAndPid time consume:7
08-01 09:32:56.520 3460-3484/? I/HwSystemManager: HoldService:preHoldShow start!
08-01 09:32:56.520 3460-3484/? I/HwSystemManager: HoldService:The prePermissionType is: 1
08-01 09:32:56.670 14342-15181/? A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x28648c1c in tid 15181 (Thread-2851)
08-01 09:32:56.680 14342-14342/? I/View: ssignParent(ViewParent parent) parent is: android.view.ViewRootImpl@1364c9d
08-01 09:32:56.690 14342-15185/? I/System: core_booster, getBoosterConfig = false
08-01 09:32:56.690 14342-15185/? I/System.out: [CDS]rx timeout:10000
08-01 09:32:56.690 14342-15185/? I/System.out: [socket][0] connection openapi.baidu.com/111.202.114.136:443;LocalPort=33170(8000)
08-01 09:32:56.690 14342-15185/? I/System.out: [CDS]connect[openapi.baidu.com/111.202.114.136:443] tm:8
08-01 09:32:56.730 2530-2530/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-01 09:32:56.730 2530-2530/? I/DEBUG: Build fingerprint: 'HUAWEI/M2/HWMozart:5.1.1/HUAWEIM2-801W/C233B009:user/release-keys'
08-01 09:32:56.730 2530-2530/? I/DEBUG: Revision: '0'
08-01 09:32:56.730 2530-2530/? I/DEBUG: ABI: 'arm'
08-01 09:32:56.730 2530-2530/? I/DEBUG: pid: 14342, tid: 15181, name: Thread-2851  >>> com.jiaxun.aruil <<<
08-01 09:32:56.730 2530-2530/? I/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x28648c1c
08-01 09:32:56.740 2530-2530/? I/DEBUG:     r0 28648bf0  r1 dead4321  r2 707c7578  r3 00000004
08-01 09:32:56.740 2530-2530/? I/DEBUG:     r4 0000005e  r5 702c3bd8  r6 12c02a10  r7 dead4321
08-01 09:32:56.740 2530-2530/? I/DEBUG:     r8 dcd02230  r9 abbb8bc8  sl 00000000  fp 70b16ab0
08-01 09:32:56.740 2530-2530/? I/DEBUG:     ip 00000000  sp dcd01db0  lr 731b2c7d  pc 732d0aca  cpsr 800e0030
08-01 09:32:56.740 2530-2530/? I/DEBUG: backtrace:
08-01 09:32:56.740 2530-2530/? I/DEBUG:     #00 pc 007c2aca  /data/dalvik-cache/arm/system@[email protected]
08-01 09:32:56.740 2530-2530/? I/DEBUG:     #01 pc 006a4c7b  /data/dalvik-cache/arm/system@[email protected]
08-01 09:32:56.840 29491-14948/? I/System.out: [CDS]EAGAIN in Recvfrom
08-01 09:32:56.840 29491-14948/? I/System.out: [CDS]read byte is 0
08-01 09:32:56.840 29491-14948/? I/System.out: [CDS]close[50561]
08-01 09:32:56.840 29491-14948/? I/System.out: close [socket][/0.0.0.0:50561]
08-01 09:32:56.840 29491-14948/? I/System: core_booster, getBoosterConfig = false
08-01 09:32:56.840 29491-14948/? I/System.out: [CDS]rx timeout:20000
08-01 09:32:56.840 29491-14948/? I/System.out: [socket][233] connection amdc.m.taobao.com/106.11.42.153:80;LocalPort=34321(20000)
08-01 09:32:56.840 29491-14948/? I/System.out: [CDS]connect[amdc.m.taobao.com/106.11.42.153:80] tm:20
08-01 09:32:56.850 29491-14948/? I/System.out: [socket][/192.168.60.153:34321] connected
08-01 09:32:57.160 2530-2530/? I/DEBUG: Tombstone written to: /data/tombstones/tombstone_02
08-01 09:32:57.160 3164-15189/? W/ActivityManager:   Force finishing activity 1 com.jiaxun.aruil/com.jiaxun.im.mvp.view.baiduvoice.ActivityOffline
08-01 09:32:57.160 3164-3191/? I/BootReceiver: Copying /data/tombstones/tombstone_02 to DropBox (SYSTEM_TOMBSTONE)
08-01 09:32:57.170 3164-15189/? I/HwWindowManagerService: setFocusedApp token: Token{fb2c384 ActivityRecord{12352816 u0 com.jiaxun.aruil/com.jiaxun.ar.mvp.view.activity.LeadingMainActivity t151}} requestedOrientation: 0
08-01 09:32:57.170 3164-15189/? W/ActivityManager:   Force finishing activity 2 com.jiaxun.aruil/com.jiaxun.ar.mvp.view.activity.LeadingMainActivity
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{4040e73 u0 android} hase children size:0
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{1e871ecf u0 android} hase children size:0
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{23ff43a u0 android} hase children size:0
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{35e86ce1 u0 android} hase children size:0
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{341df61d u0 android} hase children size:0
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{2f7210b6 u0 android} hase children size:0
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{1fcda08d u0 android} hase children size:0
08-01 09:32:57.180 3164-3266/? I/HwWindowManagerService: this win:Window{10c31895 u0 com.android.systemui} hase children size:0
08-01 09:32:57.180 3164-3190/? W/ActivityManager: Skipping native crash dialog of ProcessRecord{7ad64b3 14342:com.jiaxun.aruil/u0a312}






07-31 15:51:49.581 485-2576/system_process V/WindowManager: Adding window Window{471b1dd u0 com.jiaxun.aruil/com.jiaxun.im.mvp.view.baiduvoice.ActivityOffline} at 4 of 10 (after Window{3a239ff9 u0 com.jiaxun.aruil/com.jiaxun.ar.mvp.view.activity.LeadingMainActivity})
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: can't call android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo() on instance of com.jiaxun.ar.UiApplication
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]     in call to CallObjectMethodV
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65] "Thread-333" prio=5 tid=55 Runnable
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   | group="main" sCount=0 dsCount=0 obj=0x134470a0 self=0x8e44cc00
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   | sysTid=4354 nice=0 cgrp=default sched=0/0 handle=0x6b836380
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   | state=R schedstat=( 9585666 6180002 20 ) utm=0 stm=0 core=0 HZ=100
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   | stack=0x69b62000-0x69b64000 stackSize=1012KB
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   | held mutexes= "mutator lock"(shared held)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #00 pc 00004ef0  /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #01 pc 000036d5  /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #02 pc 00243599  /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+68)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #03 pc 00227941  /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+144)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #04 pc 000b099b  /system/lib/libart.so (art::JniAbort(char const*, char const*)+582)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #05 pc 000b10e1  /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #06 pc 000b1c9b  /system/lib/libart.so (art::ScopedCheck::CheckVirtualMethod(_jobject*, _jmethodID*)+250)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #07 pc 000b8a07  /system/lib/libart.so (art::CheckJNI::CallObjectMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list)+70)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #08 pc 00045d39  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #09 pc 0004eb47  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #10 pc 0004d509  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #11 pc 00021043  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #12 pc 00026b93  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.666 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #13 pc 00026daf  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #14 pc 0001dd91  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #15 pc 0001e993  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #16 pc 0001f785  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #17 pc 00056501  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #18 pc 0005641d  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #19 pc 000574df  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #20 pc 0004880f  /data/app/com.jiaxun.aruil-2/lib/arm/libBaiduSpeechSDK.so (???)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #21 pc 00016eaf  /system/lib/libc.so (__pthread_start(void*)+30)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   native: #22 pc 00014deb  /system/lib/libc.so (__start_thread+6)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]   (no managed stack frames)
07-31 15:51:49.667 4227-4354/com.jiaxun.aruil A/art: art/runtime/check_jni.cc:65]

猜你喜欢

转载自blog.csdn.net/w690333243/article/details/81279915