# xfvoice **Repository Path**: qjb_home/xfvoice ## Basic Information - **Project Name**: xfvoice - **Description**: 讯飞语音转文字 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-04-22 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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 ``` ## 错误处理 #### IOS ``` 错误描述: `It appears that your application still contains the default signing identifier. Try replacing 'com.example' with your signing id in Xcode:` ``` ![修改示例](err1.png)