xfvoice 1.0.3

xfvoice #

科大讯飞语音识别插件 A plugin for xunfei dictation for iOS and Android.

Install #

First, add xfvoice as a dependency in your pubspec.yaml file.

Setting #

Set privacy on iOS in Info.plist


Set privacy on Android in AndroidManifest.xml

<!--连接网络权限,用于执行云端语音能力 -->
<uses-permission android:name="android.permission.INTERNET"/>
<!--获取手机录音机使用权限,听写、识别、语义理解需要用到此权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!--读取网络信息状态 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--获取当前wifi状态 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!--允许程序改变网络连接状态 -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<!--读取手机信息权限 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!--读取联系人权限,上传联系人需要用到此权限 -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<!--外存储写权限,构建语法需要用到此权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--外存储读权限,构建语法需要用到此权限 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!--配置权限,用来记录应用配置信息 -->
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<!--定位信息是敏感信息,可通过Setting.setLocationEnable(false)关闭定位请求 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--如需使用人脸识别,还要添加:摄相头权限,拍照需要用到 -->
<uses-permission android:name="android.permission.CAMERA" />

Usage #

final voice = XFVoice.shared;
voice.init(appIdIos: 'the app id for ios', appIdAndroid: 'the app id for android');
  • Set the parameter. Class XFVoiceParam is usefull.
    // 请替换成你的appid
    voice.init(appIdIos: '5d133a41', appIdAndroid: '5d133aae');
    final param = new XFVoiceParam();
    param.domain = 'iat';
    // param.asr_ptt = '0';   //取消注释可去掉标点符号
    param.asr_audio_path = 'audio.pcm';
    param.result_type = 'json'; //可以设置plain
    final map = param.toMap();
    map['dwa'] = 'wpgs';        //设置动态修正,开启动态修正要使用json类型的返回格式
  • Start dictation. Use XFVoiceListener for listen on the callback.
final listener = XFVoiceListener(
      onVolumeChanged: (volume) {
      onResults: (String result, isLast) {
      onCompleted: (Map<dynamic, dynamic> errInfo, String filePath) {
voice.start(listener: listener);

The result type is based on the parameter result_type you setted before. It may be json/xml/plain.

  • Stop dictate.

Important #

The binary downloaded from xunfei is bind with you appid.
So, when you use this plugin, you should replace the binary in both Android and iOS project.





0.0.1 #

  • iOS support.

1.0.0 #

  • Android support.

1.0.1 #

  • fix: result is null on last in iOS.

1.0.2 #

  • fix: combine result Strings in Android.

1.0.3 #

  • fix: adapt the json result and add accent support.


xfvoice_example #

Demonstrates how to use the xfvoice plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  xfvoice: ^1.0.3

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:xfvoice/xfvoice.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 18, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Fix lib/xfvoice.dart. (-15.25 points)

Analysis of lib/xfvoice.dart reported 33 hints, including:

line 213 col 10: Name non-constant identifiers using lowerCamelCase.

line 215 col 10: Name non-constant identifiers using lowerCamelCase.

line 217 col 10: Name non-constant identifiers using lowerCamelCase.

line 218 col 10: Name non-constant identifiers using lowerCamelCase.

line 219 col 10: Name non-constant identifiers using lowerCamelCase.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

The package description is too short. (-15 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies