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
NSMicrophoneUsageDescription
NSLocationUsageDescription
NSLocationAlwaysUsageDescription
NSContactsUsageDescription
Set privacy on Android in AndroidManifest.xml
Usage
- Init the plugin. Use the appId you register on https://www.xfyun.cn/
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类型的返回格式
voice.setParameter(map);
- Start dictation. Use
XFVoiceListener
for listen on the callback.
final listener = XFVoiceListener(
onVolumeChanged: (volume) {
print('$volume');
},
onResults: (String result, isLast) {
print(result.toString());
},
onCompleted: (Map
errInfo, String filePath) {
print('onCompleted');
}
);
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.
voice.stop();
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.
iOS
xfvoice/ios/Frameworks/iflyMSC.framework
Android
xfvoice/android/libs/Msc.jar