npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-bdasr2

v1.0.4

Published

a cordova plugin, a JS version of bdasr

Downloads

9

Readme

百度语音识别cordova插件(更新至bdasr_V3_20210628_cfe8c44.jar)

  • 这是一个百度语音识别的cordova插件。为什么使用百度语音识别,因为是免费的,识别的准确度也还挺不错的。
  • 这个插件只包含语音识别功能,不包含其他的比如唤醒、长语音功能。
  • 百度语音开发文档 http://ai.baidu.com/docs#/ASR-API/top

支持平台

  1. Android(bdasr_V3_20210628_cfe8c44.jar)
  2. iOS

安装

在线npm安装

本地安装

github文件超过100M之后只能使用LFS才能上传,但是同时也有带宽限制。为了避免各种限制,所以只能辛苦各位自行下载libBaiduSpeech.a,并放到插件的src/ios/BDSClientLib目录中。

  • 第一步,将插件下载到本地
  • 第二步,下载iOS SDK中缺少的libBaiduSpeech.a
  • 第三步,添加libBaiduSpeech.a到src/ios/BDSClientLib
  • 第四步,安装插件
cordova plugin add /your localpath --variable APIKEY=your apikey --variable SECRETKEY=your secretkey --variable APPID=your appid

在线npm安装(推荐)

在线npm安装不受任何限制,可直接安装。

cordova plugin add cordova-plugin-bdasr --variable APIKEY=your apikey --variable SECRETKEY=your secretkey --variable APPID=your appid

API使用

开启语音识别

startSpeechRecognize

代码示例

cordova.plugins.bdasr.startSpeechRecognize();

关闭语音识别

closeSpeechRecognize

代码示例

cordova.plugins.bdasr.closeSpeechRecognize();

取消语音识别

cancelSpeechRecognize

代码示例

cordova.plugins.bdasr.cancelSpeechRecognize();

事件监听

addEventListener

代码示例

// 语音识别事件监听
cordova.plugins.bdasr.addEventListener(function (res) {
  // res参数都带有一个type
  if (!res) {
    return;
  }

  switch (res.type) {
    case "asrReady": {
      // 识别工作开始,开始采集及处理数据
      $scope.$apply(function () {
        // TODO
      });
      break;
    }

    case "asrBegin": {
      // 检测到用户开始说话
      $scope.$apply(function () {
        // TODO
      });
      break;
    }

    case "asrEnd": {
      // 本地声音采集结束,等待识别结果返回并结束录音
      $scope.$apply(function () {
      // TODO
      });
      break;
    }

    case "asrText": {
      // 语音识别结果
      $scope.$apply(function () {
        var message = angular.fromJson(res.message);
        var results = message["results_recognition"];
      });
      break;
    }

    case "asrFinish": {
      // 语音识别功能完成
      $scope.$apply(function () {
        // TODO
      });
      break;
    }

    case "asrCancel": {
      // 语音识别取消
      $scope.$apply(function () {
        // TODO
      });
      break;
    }

    default:
      break;
  }

}, function (err) {
   alert("语音识别错误");
});

写在最后

因为对android开发并不是很熟悉,所以特此记录在开发插件的android端时遇到的一些问题

  1. 加载so库,对应不同的平台,需要添加不同平台的.so文件
<source-file src="src/android/libs/armeabi/libBaiduSpeechSDK.so" target-dir="libs/armeabi"/>
<source-file src="src/android/libs/armeabi/libvad.dnn.so" target-dir="libs/armeabi"/>

<source-file src="src/android/libs/x86_64/libBaiduSpeechSDK.so" target-dir="libs/x86_64"/>
<source-file src="src/android/libs/x86_64/libvad.dnn.so" target-dir="libs/x86_64"/>

<source-file src="src/android/libs/x86/libBaiduSpeechSDK.so" target-dir="libs/x86"/>
<source-file src="src/android/libs/x86/libvad.dnn.so" target-dir="libs/x86"/>

<source-file src="src/android/libs/arm64-v8a/libBaiduSpeechSDK.so" target-dir="libs/arm64-v8a"/>
<source-file src="src/android/libs/arm64-v8a/libvad.dnn.so" target-dir="libs/arm64-v8a"/>

<source-file src="src/android/libs/armeabi-v7a/libBaiduSpeechSDK.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/libs/armeabi-v7a/libvad.dnn.so" target-dir="libs/armeabi-v7a"/>
  1. PermissionHelper.requestPermission()方法封装了动态获取权限的代码 动态获取权限的回调方法:
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {})