更新记录

1.0.3(2022-07-21)

增加音量回调

1.0.2(2022-07-05)

优化提示信息

1.0.1(2022-07-04)

更新唤醒时的错误提示

查看更多

平台兼容性

Android Android CPU类型 iOS
适用版本区间:5.0 - 11.0 armeabi-v7a:支持,arm64-v8a:支持,x86:未测试 ×

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


--- 百度语音唤醒及语音识别插件(支持自定义参数)


配置

购买插件,选择该插件绑定的项目。

在HBuilderX里找到项目,在manifest的app模块配置中不要勾选Speech模块,否则会冲突。

在云平台创建语音技术应用时需填写Android语音包名,否则会返回错误'Wakeup engine has no license'

百度AI开放平台导出唤醒词文件 'WakeUp.bin',放在本项目的 'static/wakeup/'目录下,如不存在此目录就新建

在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块。

根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。

打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。

开发完毕后正式云打包

调用方式

 const bd= uni.requireNativePlugin("amwhyh-BdspeechByCd")
 //初使化
 bd.init({appid:'xx', key:'xx',secret:'xx'},function(e){
    console.log(e)
 })
 //唤醒 参数参照百度文档
 bd.wakeup({},function(e){ 
     if(e.code==200){
        console.log("等待唤醒")
     }

     if(e.code==209){
        console.log("唤醒成功!唤醒词"+e.words)
     }

  });
  //停止唤醒
 bd.stopWakeup();
 /*
 * 参数非必须,按需求选填参数
 * enableOffline:true 开启离线命令词  
 * 需配合 decoder 参数和 grammar 文件路径   同时才生效
 * decoder:2,离在线的并行策略
 *  grammar 路径如果使用项目路径("static/wakeup/")需加 #sys_path#  
 */
  //启动语音识别 具体参数参照[百度文档](https://ai.baidu.com/ai-doc/SPEECH/bkh07sd0m)
  bd.startRecognize({enableOffline:true,decoder:2,grammar:"#sys_path#baidu_speech_grammar.bsg"},
  function(res){
     //识别结果
     if(res.code==200 ){
          console.log(res.words)
     }
       // "accept-audio-volume":true 开启后有语音音量数据回调   【volume】当前音量【volumePercent】当前音量的相对值(0-100)
     if(e.code==202){
        console.log(res.volumePercent)
        console.log(res.volume)
     }
     //一句话最终结果
     if(res.code==201 ){
         console.log(res.words)
     }
});

//停止语音识别   key参数包含 【stop】提前结束录音等待识别结果。   key参数包含【cancel】  取消后将立即停止不会返回识别结果。
 //无参时注销本次识别 需要再次识别需要重新bd.startRecognize()
bd.stopRecognize({stop:"" });

回调参数

{
  code: 2xx ,//成功 
  errorMessge: "" , //当CODE为非2xx时提示错误信息
  words:""   //成功唤醒时的唤醒词
}

问题

 code:11 ,errorMessge:'Wakeup engine has no license'   
 申请百度语音服务时要认证包名,把在云打包时的Android包名填上就可以了
 code:3 ,errorMessge:'Recorder open failed'   
 麦克风权限没有授权,手动打开权限
 code:4 subErrorCode:4004,words:"App name unknown Open api duration limit reached"
 没有语音识别额度了
  1,免费赠送的额度没有领取
  2,短语音识别是短语音的额度,开启长语音之后是实时语音的额度, 确认账号的调用的接口额度是否正常。 
  3,领取额度的PID 和 在使用的PID不一至  (默认【1537】中文普通话)
  4,免费的额度用完了或过期了,需付费使用

百度KEY 参数对照

ASR_START = "asr.start";
ASR_STOP = "asr.stop";
ASR_CANCEL = "asr.cancel";
ASR_KWS_LOAD_ENGINE = "asr.kws.load";
ASR_KWS_UNLOAD_ENGINE = "asr.kws.unload";
ASR_UPLOAD_WORDS = "asr.upload.words";
ASR_UPLOAD_CANCEL = "asr.upload.cancel";
WAKEUP_START = "wp.start";
WAKEUP_STOP = "wp.stop";
WAKEUP_LOAD_ENGINE = "wp.load";
WAKEUP_UNLOAD_ENGINE = "wp.unload";
ASR_UPLOAD_CONTRACT = "asr.upload.contract";
UPLOADER_START = "uploader.start";
UPLOADER_CANCEL = "uploader.cancel";
CALLBACK_EVENT_ASR_READY = "asr.ready";
CALLBACK_EVENT_ASR_BEGIN = "asr.begin";
CALLBACK_EVENT_ASR_AUDIO = "asr.audio";
CALLBACK_EVENT_ASR_VOLUME = "asr.volume";
CALLBACK_EVENT_ASR_END = "asr.end";
CALLBACK_EVENT_ASR_PARTIAL = "asr.partial";
CALLBACK_EVENT_ASR_FINISH = "asr.finish";
CALLBACK_EVENT_ASR_EXIT = "asr.exit";
CALLBACK_EVENT_ASR_CANCEL = "asr.cancel";
CALLBACK_EVENT_ASR_ERROR = "asr.error";
CALLBACK_EVENT_ASR_LOADED = "asr.loaded";
CALLBACK_EVENT_ASR_UNLOADED = "asr.unloaded";
CALLBACK_EVENT_ASR_SERIALNUMBER = "asr.sn";
CALLBACK_EVENT_ASR_LOG = "asr.log";
CALLBACK_EVENT_UPLOAD_COMPLETE = "asr.upload.complete";
CALLBACK_EVENT_ASR_LONG_SPEECH = "asr.long-speech.finish";
ASR_CALLBACk_NAME = "ASR.callback";
WAKEUP_CALLBACK_NAME = "WAKEUP.callback";
UPLOAD_CALLBACK_NAME = "UPLOAD.callback";
CALLBACK_ASR_STATUS = "cb.asr.status.int";
strCALLBACK_ASR_LEVEL = "cb.asr.level.int";
CALLBACK_ASR_RESULT = "cb.asr.result.string";
CALLBACK_WAK_STATUS = "cb.wak.status.int";
CALLBACK_WAK_RESULT = "cb.wak.result.string";
CALLBACK_ERROR_DOMAIN = "cb.error.domain.int16_t";
CALLBACK_ERROR_CODE = "cb.error.code.int16_t";
CALLBACK_ERROR_DESC = "cb.error.desc.string";
CALLBACK_EVENT_UNIT_FINISH = "unit.finish";
SOUND_START = "sound_start";
SOUND_END = "sound_end";
SOUND_SUCCESS = "sound_success";
SOUND_ERROR = "sound_error";
SOUND_CANCEL = "sound_cancel";
CALLBACK_EVENT_WAKEUP_STARTED = "wp.enter";
CALLBACK_EVENT_WAKEUP_READY = "wp.ready";
CALLBACK_EVENT_WAKEUP_STOPED = "wp.exit";
CALLBACK_EVENT_WAKEUP_LOADED = "wp.loaded";
CALLBACK_EVENT_WAKEUP_UNLOADED = "wp.unloaded";
CALLBACK_EVENT_WAKEUP_ERROR = "wp.error";
CALLBACK_EVENT_WAKEUP_SUCCESS = "wp.data";
CALLBACK_EVENT_WAKEUP_AUDIO = "wp.audio";
CALLBACK_EVENT_UPLOAD_FINISH = "uploader.finish";
LOG_LEVEL = "log_level";
LANGUAGE = "language";
CONTACT = "contact";
VAD = "vad";
VAD_MFE = "mfe";
VAD_MODEL = "model-vad";
VAD_DNN = "dnn";
VAD_TOUCH = "touch";
SAMPLE_RATE = "sample";
PAM = "decoder-server.pam";
NLU = "nlu";
PROP = "prop";
PUBLIC_DECODER = false;
IN_FILE = "infile";
AUDIO_MILLS = "audio.mills";
AUDIO_SOURCE = "audio.source";
OUT_FILE = "outfile";
ACCEPT_AUDIO_DATA = "accept-audio-data";
ACCEPT_AUDIO_VOLUME = "accept-audio-volume";
APP_KEY = "key";
SECRET = "secret";
URL = "decoder-server.url";
// 1537 普通话 ,19364 普通话远场 ,
PID = "pid";
LMID = "lm_id";
APP_NAME = "decoder-server.app";

DEC_TYPE = "dec-type";
DECODER = "decoder";
ASR_VAD_RES_FILE_PATH = "vad.res-file";
   //超时
VAD_ENDPOINT_TIMEOUT = "vad.endpoint-timeout";
    //禁用长语音
BDS_ASR_ENABLE_LONG_SPEECH = "enable.long.speech";
ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH = "grammar";
ASR_OFFLINE_ENGINE_DAT_FILE_PATH = "asr-base-file-path";
ASR_OFFLINE_ENGINE_LICENSE_FILE_PATH = "license-file-path";
SLOT_DATA = "slot-data";
    // 禁用标点
DISABLE_PUNCTUATION = "disable-punctuation";
KWS_TYPE = "kws-type";
APP_ID = "appid";
APP_SN = "appsn";
DEV = "dev";
WP_DAT_FILEPATH = "wakeup_dat_filepath";
WP_WORDS_FILE = "kws-file";
WP_WORDS = "words";
ENABLE_HTTPDNS = "enable-httpdns";
WP_VAD_ENABLE = "wp.vad_enable";
WP_ENGINE_LICENSE_FILE_PATH = "license-file-path";
BOT_SESSION_LIST = "bot_session_list";
BOT_ID = "bot_id";
BOT_SESSION = "bot_session";
BOT_SESSION_ID = "bot_session_id";
ASR_ENABLE_NUMBERFORMAT = "enable.numberformat";
ASR_PUNCTUATION_MODE = "punctuation-mode";

隐私、权限声明

1. 本插件需要申请的系统权限列表:

<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

百度是否采集参考其官方说明 https://ai.baidu.com/ai-doc/SPEECH/Ek39uxgre

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问