Code Monkey home page Code Monkey logo

flutter_rsa's Introduction

voice_rsa 语音文件识别 插件

flutter 语音文件 识别 (语音转文本) (英语)

  • Android 端采用百度语音识别sdk(百度收费)
  • iOS 端采用 系统语音识别功能(免费) 注意:格式
  • Android 端需要 pcm
  • iOS mp3 或m4a 都行,pcm 无法识别
  • 重要... 需要真机测试 模拟器报错

配置

Android

Manifest 配置

  1. 需要添加权限
<uses-permission android:name="android.permission.RECORD_AUDIO" />
  1. 重要重要重要 项目中而配置 在 Android 应用的 Manifest 文件中设置的属性,它位于 标签内。这个设置告诉 Android 系统是否需要在安装时解压你的应用的原生库 (.so 文件)。
android:extractNativeLibs="true"

示例

//百度识别需要录音权限 虽然是文件识别也需要否则报错
    await requestPermission();
      String cacheFilePath = await localPath();
      //path 是pcm 格式文件,路径是全路径  baiduAppId相关 百度识别后台查看
      var result = await voiceRsaPlugin.getVoiceAsr('', params: {
        'appid': 'baiduAppId',
        'key': 'baiduKey',
        'secret': 'baiduSecret',
        'infile': cacheFilePath,
      });
      if (result != null) {
        if (result['code'] == 0) {//识别正确的结果
          var message = result['message'] ?? '';
        } else {
          // 异常识别
          if (result['message'] == "No speech detected") {
            result['message'] = "未检测到语音";
          }
          throw result['message'] ?? '识别异常';
        }
      } else {
        throw '识别异常';
      }

iOS

ios info 配置权限 Privacy - Speech Recognition Usage Description

  1. 检查是否有权限

示例:

  var requestResult = await voiceRsaPlugin.requestAuthorization();
  switch (requestResult) {
    case RsaAuthorization.agree:
      break;
    case RsaAuthorization.disagree:
      // ToastUtils.show('请在设置中同意语音识别权限');
      return;
    case RsaAuthorization.unAvailable:
      // ToastUtils.show('该设备不支持语音识别');
      return;
    case RsaAuthorization.unknown:
      // ToastUtils.show('语音识别权限未知');
      return;
  }


  String cacheFilePath = await localPath();
  var result = await voiceRsaPlugin.getVoiceAsr(cacheFilePath);
  if (result != null) {
    if (result['code'] == 0) {//识别正确的结果
      var message = result['message'] ?? '';
    } else {
      // 异常识别
      if (result['message'] == "No speech detected") {
        result['message'] = "未检测到语音";
      }
      throw result['message'] ?? '识别异常';
    }
  } else {
    throw '识别异常';
  }
}

flutter_rsa's People

Contributors

zyjian avatar

Stargazers

luoyi avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.