├── README.md ├── plugin.xml ├── src ├── android │ ├── assets │ │ ├── call.bnf │ │ ├── grammar_sample.abnf │ │ ├── iattest.wav │ │ ├── iflytek │ │ │ ├── recognize.xml │ │ │ ├── voice_bg.9.png │ │ │ ├── voice_empty.png │ │ │ ├── voice_full.png │ │ │ ├── waiting.png │ │ │ └── warning.png │ │ ├── keys │ │ └── userwords │ ├── libs │ │ ├── Msc.jar │ │ ├── Sunflower.jar │ │ ├── arm64-v8a │ │ │ └── libmsc.so │ │ ├── armeabi-v7a │ │ │ └── libmsc.so │ │ └── armeabi │ │ │ └── libmsc.so │ ├── res │ │ ├── layout │ │ │ └── activity_xunfei_dialog.xml │ │ ├── values │ │ │ └── strings.xml │ │ └── xml │ │ │ ├── iat_setting.xml │ │ │ ├── ise_settings.xml │ │ │ ├── tts_setting.xml │ │ │ └── understand_setting.xml │ └── src │ │ └── com │ │ └── thomas │ │ └── xunfeilistenspeaking │ │ ├── IatSettings.java │ │ ├── JsonParser.java │ │ ├── SettingTextWatcher.java │ │ ├── XunfeiDialogActivity.java │ │ └── XunfeiListenSpeaking.java └── ios │ ├── CDVSpeech.h │ ├── CDVSpeech.m │ └── iflyMSC.framework │ ├── Headers │ ├── IFlyContact.h │ ├── IFlyDataUploader.h │ ├── IFlyDebugLog.h │ ├── IFlyISVDelegate.h │ ├── IFlyISVRecognizer.h │ ├── IFlyMSC.h │ ├── IFlyPcmRecorder.h │ ├── IFlyRecognizerView.h │ ├── IFlyRecognizerViewDelegate.h │ ├── IFlyResourceUtil.h │ ├── IFlySetting.h │ ├── IFlySpeechConstant.h │ ├── IFlySpeechError.h │ ├── IFlySpeechEvaluator.h │ ├── IFlySpeechEvaluatorDelegate.h │ ├── IFlySpeechEvent.h │ ├── IFlySpeechRecognizer.h │ ├── IFlySpeechRecognizerDelegate.h │ ├── IFlySpeechSynthesizer.h │ ├── IFlySpeechSynthesizerDelegate.h │ ├── IFlySpeechUnderstander.h │ ├── IFlySpeechUtility.h │ ├── IFlyTextUnderstander.h │ ├── IFlyUserWords.h │ ├── IFlyVoiceWakeuper.h │ └── IFlyVoiceWakeuperDelegate.h │ └── iflyMSC └── www ├── Speech.js └── cordova-plugin-xunfeiListenSpeaking.js /README.md: -------------------------------------------------------------------------------- 1 | # cordova-plugin-IFlyspeech 2 | 科大讯飞的语音听说读写的cordova插件 3 | ### Supported Platforms 4 | 5 | - iOS 6 | - android 7 | 8 | ## Installation 9 | 10 | cordova plugin add https://github.com/Edc-zhang/cordova-plugin-IFlyspeech 11 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | cordova-plugin-xunfeiListenSpeaking 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 584e7225 86 | 本示例为讯飞语音Android平台开发者提供语音听写、语法识别、语义理解和语音合成等代码样例,旨在让用户能够依据该示例快速开发出基于语音接口的应用程序。 87 | 科大讯飞作为中国最大的智能语音技术提供商,在智能语音技术领域有着长期的研究积累,并在中文语音合成、语音识别、口语评测等多项技术上拥有国际领先的成果。科大讯飞是我国唯一以语音技术为产业化方向的“国家863计划成果产业化基地”… 88 | iFLYTEK is a national key software enterprise dedicated to the research of intelligent speech and language technologies, development of software and chip products, provision of speech information services, and integration of E-government systems. The intelligent speech technology of iFLYTEK, the core technology of the company, represents the top level in the world. 89 | \t上传内容为:\n\t#ABNF 1.0 gb2312;\n\tlanguage zh-CN;\n\tmode voice;\n\troot $main;\n\t$main = $place1 到$place2 ;\n\t$place1 = 北京 | 武汉 | 南京 | 天津 | 东京;\n\t$place2 = 上海 | 合肥; 90 | \t您可以说:\n\t今天的天气怎么样?\n\t北京到上海的火车?\n\t有什么好吃的?\n\t上海外滩有哪些酒店?\n\n\t更多语义请登录:\n\thttp://osp.voicecloud.cn/ \n\t配置您的专属语义吧! 91 | 92 | 请开始说话… 93 | 开始音频流识别 94 | 上传联系人 95 | 上传用户词表 96 | 上传成功 97 | 词表下载失败或内容为空 98 | 下载成功 99 | iat_show 100 | 显示听写界面 101 | 结果动态修正 102 | 103 | 取消语音 104 | 105 | 106 | 本地合成 107 | 在线合成 108 | 109 | 110 | local 111 | cloud 112 | 113 | 114 | 小燕—女青、中英、普通话 115 | 小宇—男青、中英、普通话 116 | 凯瑟琳—女青、英 117 | 亨利—男青、英 118 | 玛丽—女青、英 119 | 小研—女青、中英、普通话 120 | 小琪—女青、中英、普通话 121 | 小峰—男青、中英、普通话 122 | 小梅—女青、中英、粤语 123 | 小莉—女青、中英、台湾普通话 124 | 小蓉—女青、中、四川话 125 | 小芸—女青、中、东北话 126 | 小坤—男青、中、河南话 127 | 小强—男青、中、湖南话 128 | 小莹—女青、中、陕西话 129 | 小新—男童、中、普通话 130 | 楠楠—女童、中、普通话 131 | 老孙—男老、中、普通话 132 | 133 | 134 | xiaoyan 135 | xiaoyu 136 | catherine 137 | henry 138 | vimary 139 | vixy 140 | xiaoqi 141 | vixf 142 | xiaomei 143 | xiaolin 144 | xiaorong 145 | xiaoqian 146 | xiaokun 147 | xiaoqiang 148 | vixying 149 | xiaoxin 150 | nannan 151 | vils 152 | 153 | 154 | 正常 155 | 高兴 156 | 悲伤 157 | 生气 158 | 159 | 160 | neutral 161 | happy 162 | sad 163 | angry 164 | 165 | 166 | 通话 167 | 系统 168 | 铃声 169 | 音乐 170 | 闹铃 171 | 通知 172 | 173 | 174 | 0 175 | 1 176 | 2 177 | 3 178 | 4 179 | 5 180 | 181 | 缓冲进度为%d%%,播放进度为%d%% 182 | 183 | 184 | 普通话 185 | 粤语 186 | 河南话 187 | 英语 188 | 189 | 190 | mandarin 191 | cantonese 192 | henanese 193 | en_us 194 | 195 | 196 | "[word]\napple\nbanana\norange" 197 | "The quick brown fox jumps over the lazy dog." 198 | "知,痴,是" 199 | "磁铁,率领,脆弱,动手,古筝" 200 | "一座座雪峰插入云霄,峰顶银光闪闪,大大小小的湖泊,像颗颗宝石镶嵌在彩带般的沟谷中。" 201 | 202 | 英语 203 | 汉语 204 | 205 | 206 | en_us 207 | zh_cn 208 | 209 | 210 | 单字 211 | 词语 212 | 句子 213 | 214 | 215 | read_syllable 216 | read_word 217 | read_sentence 218 | 219 | 220 | plain 221 | complete 222 | 223 | 224 | 225 | 有标点 226 | 无标点 227 | 228 | 229 | 1 230 | 0 231 | 232 | 233 | 开启 234 | 关闭 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | -------------------------------------------------------------------------------- /src/android/assets/call.bnf: -------------------------------------------------------------------------------- 1 | #BNF+IAT 1.0 UTF-8; 2 | !grammar call; 3 | !slot ; 4 | !slot ; 5 | !slot ; 6 | !slot ; 7 | !start ; 8 | :[][]|[][]; 9 | :张海洋; 10 | :我要|我想|我想要; 11 | :打电话; 12 | :给; -------------------------------------------------------------------------------- /src/android/assets/grammar_sample.abnf: -------------------------------------------------------------------------------- 1 | #ABNF 1.0 UTF-8; 2 | language zh-CN; 3 | mode voice; 4 | 5 | root $main; 6 | $main = $place1 到 $place2; 7 | $place1 = 北京|武汉|南京|天津|东京; 8 | $place2 = 上海|合肥; -------------------------------------------------------------------------------- /src/android/assets/iattest.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/iattest.wav -------------------------------------------------------------------------------- /src/android/assets/iflytek/recognize.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/iflytek/recognize.xml -------------------------------------------------------------------------------- /src/android/assets/iflytek/voice_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/iflytek/voice_bg.9.png -------------------------------------------------------------------------------- /src/android/assets/iflytek/voice_empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/iflytek/voice_empty.png -------------------------------------------------------------------------------- /src/android/assets/iflytek/voice_full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/iflytek/voice_full.png -------------------------------------------------------------------------------- /src/android/assets/iflytek/waiting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/iflytek/waiting.png -------------------------------------------------------------------------------- /src/android/assets/iflytek/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/iflytek/warning.png -------------------------------------------------------------------------------- /src/android/assets/keys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/assets/keys -------------------------------------------------------------------------------- /src/android/assets/userwords: -------------------------------------------------------------------------------- 1 | {"userword":[{"name":"我的常用词","words":["佳晨实业","蜀南庭苑","高兰路","复联二"]},{"name":"我的好友","words":["李馨琪","鹿晓雷","张集栋","周家莉","叶震珂","熊泽萌"]}]} -------------------------------------------------------------------------------- /src/android/libs/Msc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/libs/Msc.jar -------------------------------------------------------------------------------- /src/android/libs/Sunflower.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/libs/Sunflower.jar -------------------------------------------------------------------------------- /src/android/libs/arm64-v8a/libmsc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/libs/arm64-v8a/libmsc.so -------------------------------------------------------------------------------- /src/android/libs/armeabi-v7a/libmsc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/libs/armeabi-v7a/libmsc.so -------------------------------------------------------------------------------- /src/android/libs/armeabi/libmsc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/android/libs/armeabi/libmsc.so -------------------------------------------------------------------------------- /src/android/res/layout/activity_xunfei_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | XunfeiSpeaking 3 | 4 | 5 | 584e7225 6 | 本示例为讯飞语音Android平台开发者提供语音听写、语法识别、语义理解和语音合成等代码样例,旨在让用户能够依据该示例快速开发出基于语音接口的应用程序。 7 | 科大讯飞作为中国最大的智能语音技术提供商,在智能语音技术领域有着长期的研究积累,并在中文语音合成、语音识别、口语评测等多项技术上拥有国际领先的成果。科大讯飞是我国唯一以语音技术为产业化方向的“国家863计划成果产业化基地”… 8 | iFLYTEK is a national key software enterprise dedicated to the research of intelligent speech and language technologies, development of software and chip products, provision of speech information services, and integration of E-government systems. The intelligent speech technology of iFLYTEK, the core technology of the company, represents the top level in the world. 9 | \t上传内容为:\n\t#ABNF 1.0 gb2312;\n\tlanguage zh-CN;\n\tmode voice;\n\troot $main;\n\t$main = $place1 到$place2 ;\n\t$place1 = 北京 | 武汉 | 南京 | 天津 | 东京;\n\t$place2 = 上海 | 合肥; 10 | \t您可以说:\n\t今天的天气怎么样?\n\t北京到上海的火车?\n\t有什么好吃的?\n\t上海外滩有哪些酒店?\n\n\t更多语义请登录:\n\thttp://osp.voicecloud.cn/ \n\t配置您的专属语义吧! 11 | 12 | 请开始说话… 13 | 开始音频流识别 14 | 上传联系人 15 | 上传用户词表 16 | 上传成功 17 | 词表下载失败或内容为空 18 | 下载成功 19 | iat_show 20 | 显示听写界面 21 | 结果动态修正 22 | 23 | 24 | 25 | 本地合成 26 | 在线合成 27 | 28 | 29 | local 30 | cloud 31 | 32 | 33 | 小燕—女青、中英、普通话 34 | 小宇—男青、中英、普通话 35 | 凯瑟琳—女青、英 36 | 亨利—男青、英 37 | 玛丽—女青、英 38 | 小研—女青、中英、普通话 39 | 小琪—女青、中英、普通话 40 | 小峰—男青、中英、普通话 41 | 小梅—女青、中英、粤语 42 | 小莉—女青、中英、台湾普通话 43 | 小蓉—女青、中、四川话 44 | 小芸—女青、中、东北话 45 | 小坤—男青、中、河南话 46 | 小强—男青、中、湖南话 47 | 小莹—女青、中、陕西话 48 | 小新—男童、中、普通话 49 | 楠楠—女童、中、普通话 50 | 老孙—男老、中、普通话 51 | 52 | 53 | xiaoyan 54 | xiaoyu 55 | catherine 56 | henry 57 | vimary 58 | vixy 59 | xiaoqi 60 | vixf 61 | xiaomei 62 | xiaolin 63 | xiaorong 64 | xiaoqian 65 | xiaokun 66 | xiaoqiang 67 | vixying 68 | xiaoxin 69 | nannan 70 | vils 71 | 72 | 73 | 正常 74 | 高兴 75 | 悲伤 76 | 生气 77 | 78 | 79 | neutral 80 | happy 81 | sad 82 | angry 83 | 84 | 85 | 通话 86 | 系统 87 | 铃声 88 | 音乐 89 | 闹铃 90 | 通知 91 | 92 | 93 | 0 94 | 1 95 | 2 96 | 3 97 | 4 98 | 5 99 | 100 | 缓冲进度为%d%%,播放进度为%d%% 101 | 102 | 103 | 普通话 104 | 粤语 105 | 河南话 106 | 英语 107 | 108 | 109 | mandarin 110 | cantonese 111 | henanese 112 | en_us 113 | 114 | 115 | "[word]\napple\nbanana\norange" 116 | "The quick brown fox jumps over the lazy dog." 117 | "知,痴,是" 118 | "磁铁,率领,脆弱,动手,古筝" 119 | "一座座雪峰插入云霄,峰顶银光闪闪,大大小小的湖泊,像颗颗宝石镶嵌在彩带般的沟谷中。" 120 | 121 | 英语 122 | 汉语 123 | 124 | 125 | en_us 126 | zh_cn 127 | 128 | 129 | 单字 130 | 词语 131 | 句子 132 | 133 | 134 | read_syllable 135 | read_word 136 | read_sentence 137 | 138 | 139 | plain 140 | complete 141 | 142 | 143 | 144 | 有标点 145 | 无标点 146 | 147 | 148 | 1 149 | 0 150 | 151 | 152 | 开启 153 | 关闭 154 | 155 | 156 | -------------------------------------------------------------------------------- /src/android/res/xml/iat_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 18 | 19 | 25 | 26 | 33 | 34 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/android/res/xml/ise_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 19 | 20 | 27 | 28 | 33 | 34 | 39 | 40 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/android/res/xml/tts_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 16 | 22 | 28 | 29 | -------------------------------------------------------------------------------- /src/android/res/xml/understand_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 16 | 17 | 23 | 24 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/android/src/com/thomas/xunfeilistenspeaking/IatSettings.java: -------------------------------------------------------------------------------- 1 | package com.thomas.xunfeilistenspeaking; 2 | 3 | import android.os.Bundle; 4 | import android.preference.EditTextPreference; 5 | import android.preference.Preference; 6 | import android.preference.Preference.OnPreferenceChangeListener; 7 | import android.preference.PreferenceActivity; 8 | import android.view.Window; 9 | import com.thomas.xunfeilistenspeaking.SettingTextWatcher; 10 | 11 | /** 12 | * 听写设置界面 13 | */ 14 | public class IatSettings extends PreferenceActivity implements OnPreferenceChangeListener { 15 | 16 | public static final String PREFER_NAME = "com.iflytek.setting"; 17 | private EditTextPreference mVadbosPreference; 18 | private EditTextPreference mVadeosPreference; 19 | 20 | @SuppressWarnings("deprecation") 21 | public void onCreate(Bundle savedInstanceState) { 22 | requestWindowFeature(Window.FEATURE_NO_TITLE); 23 | super.onCreate(savedInstanceState); 24 | getPreferenceManager().setSharedPreferencesName(PREFER_NAME); 25 | // addPreferencesFromResource(R.xml.iat_setting); 26 | addPreferencesFromResource(getResources().getIdentifier("iat_setting","xml",getPackageName())); 27 | 28 | mVadbosPreference = (EditTextPreference)findPreference("iat_vadbos_preference"); 29 | mVadbosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this,mVadbosPreference,0,10000)); 30 | 31 | mVadeosPreference = (EditTextPreference)findPreference("iat_vadeos_preference"); 32 | mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this,mVadeosPreference,0,10000)); 33 | } 34 | @Override 35 | public boolean onPreferenceChange(Preference preference, Object newValue) { 36 | return true; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/android/src/com/thomas/xunfeilistenspeaking/JsonParser.java: -------------------------------------------------------------------------------- 1 | package com.thomas.xunfeilistenspeaking; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONObject; 5 | import org.json.JSONTokener; 6 | 7 | /** 8 | * Json结果解析类 9 | */ 10 | public class JsonParser { 11 | 12 | public static String parseIatResult(String json) { 13 | StringBuffer ret = new StringBuffer(); 14 | try { 15 | JSONTokener tokener = new JSONTokener(json); 16 | JSONObject joResult = new JSONObject(tokener); 17 | 18 | JSONArray words = joResult.getJSONArray("ws"); 19 | for (int i = 0; i < words.length(); i++) { 20 | // 转写结果词,默认使用第一个结果 21 | JSONArray items = words.getJSONObject(i).getJSONArray("cw"); 22 | JSONObject obj = items.getJSONObject(0); 23 | ret.append(obj.getString("w")); 24 | // 如果需要多候选结果,解析数组其他字段 25 | // for(int j = 0; j < items.length(); j++) 26 | // { 27 | // JSONObject obj = items.getJSONObject(j); 28 | // ret.append(obj.getString("w")); 29 | // } 30 | } 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | return ret.toString(); 35 | } 36 | 37 | public static String parseGrammarResult(String json) { 38 | StringBuffer ret = new StringBuffer(); 39 | try { 40 | JSONTokener tokener = new JSONTokener(json); 41 | JSONObject joResult = new JSONObject(tokener); 42 | 43 | JSONArray words = joResult.getJSONArray("ws"); 44 | for (int i = 0; i < words.length(); i++) { 45 | JSONArray items = words.getJSONObject(i).getJSONArray("cw"); 46 | for(int j = 0; j < items.length(); j++) 47 | { 48 | JSONObject obj = items.getJSONObject(j); 49 | if(obj.getString("w").contains("nomatch")) 50 | { 51 | ret.append("没有匹配结果."); 52 | return ret.toString(); 53 | } 54 | ret.append("【结果】" + obj.getString("w")); 55 | ret.append("【置信度】" + obj.getInt("sc")); 56 | ret.append("\n"); 57 | } 58 | } 59 | } catch (Exception e) { 60 | e.printStackTrace(); 61 | ret.append("没有匹配结果."); 62 | } 63 | return ret.toString(); 64 | } 65 | 66 | public static String parseLocalGrammarResult(String json) { 67 | StringBuffer ret = new StringBuffer(); 68 | try { 69 | JSONTokener tokener = new JSONTokener(json); 70 | JSONObject joResult = new JSONObject(tokener); 71 | 72 | JSONArray words = joResult.getJSONArray("ws"); 73 | for (int i = 0; i < words.length(); i++) { 74 | JSONArray items = words.getJSONObject(i).getJSONArray("cw"); 75 | for(int j = 0; j < items.length(); j++) 76 | { 77 | JSONObject obj = items.getJSONObject(j); 78 | if(obj.getString("w").contains("nomatch")) 79 | { 80 | ret.append("没有匹配结果."); 81 | return ret.toString(); 82 | } 83 | ret.append("【结果】" + obj.getString("w")); 84 | ret.append("\n"); 85 | } 86 | } 87 | ret.append("【置信度】" + joResult.optInt("sc")); 88 | 89 | } catch (Exception e) { 90 | e.printStackTrace(); 91 | ret.append("没有匹配结果."); 92 | } 93 | return ret.toString(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/android/src/com/thomas/xunfeilistenspeaking/SettingTextWatcher.java: -------------------------------------------------------------------------------- 1 | package com.thomas.xunfeilistenspeaking; 2 | 3 | import android.content.Context; 4 | import android.preference.EditTextPreference; 5 | import android.text.Editable; 6 | import android.text.TextUtils; 7 | import android.text.TextWatcher; 8 | import android.widget.Toast; 9 | 10 | import java.util.regex.Pattern; 11 | 12 | /** 13 | * 输入框输入范围控制 14 | */ 15 | public class SettingTextWatcher implements TextWatcher { 16 | private int editStart ; 17 | private int editCount ; 18 | private EditTextPreference mEditTextPreference; 19 | int minValue;//最小值 20 | int maxValue;//最大值 21 | private Context mContext; 22 | 23 | public SettingTextWatcher(Context context, EditTextPreference e, int min, int max) { 24 | mContext = context; 25 | mEditTextPreference = e; 26 | minValue = min; 27 | maxValue = max; 28 | } 29 | 30 | @Override 31 | public void onTextChanged(CharSequence s, int start, int before, int count) { 32 | // Log.e("demo", "onTextChanged start:"+start+" count:"+count+" before:"+before); 33 | editStart = start; 34 | editCount = count; 35 | } 36 | 37 | @Override 38 | public void beforeTextChanged(CharSequence s, int start, int count,int after) { 39 | // Log.e("demo", "beforeTextChanged start:"+start+" count:"+count+" after:"+after); 40 | } 41 | 42 | @Override 43 | public void afterTextChanged(Editable s) { 44 | if (TextUtils.isEmpty(s)) { 45 | return; 46 | } 47 | String content = s.toString(); 48 | // Log.e("demo", "content:"+content); 49 | if (isNumeric(content)) { 50 | int num = Integer.parseInt(content); 51 | if (num > maxValue || num < minValue) { 52 | s.delete(editStart, editStart+editCount); 53 | mEditTextPreference.getEditText().setText(s); 54 | Toast.makeText(mContext, "超出有效值范围", Toast.LENGTH_SHORT).show(); 55 | } 56 | }else { 57 | s.delete(editStart, editStart+editCount); 58 | mEditTextPreference.getEditText().setText(s); 59 | Toast.makeText(mContext, "只能输入数字哦", Toast.LENGTH_SHORT).show(); 60 | } 61 | } 62 | 63 | /** 64 | * 正则表达式-判断是否为数字 65 | */ 66 | public static boolean isNumeric(String str){ 67 | Pattern pattern = Pattern.compile("[0-9]*"); 68 | return pattern.matcher(str).matches(); 69 | } 70 | 71 | }; 72 | -------------------------------------------------------------------------------- /src/android/src/com/thomas/xunfeilistenspeaking/XunfeiDialogActivity.java: -------------------------------------------------------------------------------- 1 | package com.thomas.xunfeilistenspeaking; 2 | 3 | import android.app.Activity; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.os.Bundle; 8 | import android.os.Environment; 9 | import android.os.Handler; 10 | import android.util.Log; 11 | import android.widget.Toast; 12 | import com.iflytek.cloud.*; 13 | import com.iflytek.cloud.ui.RecognizerDialog; 14 | import com.iflytek.cloud.ui.RecognizerDialogListener; 15 | import com.iflytek.sunflower.FlowerCollector; 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | 19 | import java.util.HashMap; 20 | import java.util.LinkedHashMap; 21 | 22 | /** 23 | * Created by Thomas.Wang on 2017/2/10. 24 | */ 25 | public class XunfeiDialogActivity extends Activity{ 26 | 27 | private static String TAG = XunfeiDialogActivity.class.getSimpleName(); 28 | // 语音听写对象 29 | private SpeechRecognizer mIat; 30 | // 语音听写UI 31 | private RecognizerDialog mIatDialog; 32 | // 用HashMap存储听写结果 33 | private HashMap mIatResults = new LinkedHashMap(); 34 | 35 | // private EditText mResultText; 36 | private Toast mToast; 37 | private SharedPreferences mSharedPreferences; 38 | // 引擎类型 39 | private String mEngineType = SpeechConstant.TYPE_CLOUD; 40 | 41 | 42 | private Handler mHandler = new Handler(); 43 | private boolean isShowDialog; 44 | private String punc = "1"; 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(getResources().getIdentifier("activity_xunfei_dialog","layout",getPackageName())); 50 | 51 | isShowDialog = getIntent().getBooleanExtra("isShowDialog",false); 52 | punc = getIntent().getStringExtra("punc"); 53 | mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); 54 | mIat = SpeechRecognizer.createRecognizer(this, mInitListener); 55 | 56 | // 初始化听写Dialog,如果只使用有UI听写功能,无需创建SpeechRecognizer 57 | // 使用UI听写功能,请根据sdk文件目录下的notice.txt,放置布局文件和图片资源 58 | mIatDialog = new RecognizerDialog(this, mInitListener); 59 | mIatDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { 60 | @Override 61 | public void onCancel(DialogInterface dialog) { 62 | finishThisActivity(RESULT_CANCELED,getString(getId("xunfei_cancel_listen","string"))); 63 | } 64 | }); 65 | mSharedPreferences = getSharedPreferences(IatSettings.PREFER_NAME, 66 | Activity.MODE_PRIVATE); 67 | startListen(); 68 | } 69 | 70 | private void stopListen(){ 71 | if (mIat.isListening()) { 72 | mIat.stopListening(); 73 | } 74 | } 75 | private void startListen() { 76 | if (mIat.isListening()) { 77 | mIat.stopListening(); 78 | } 79 | // 移动数据分析,收集开始听写事件 80 | FlowerCollector.onEvent(this, "iat_recognize"); 81 | mIatResults.clear(); 82 | // 设置参数 83 | setParam(); 84 | 85 | // boolean isShowDialog = true; 86 | if (isShowDialog) { 87 | // 显示听写对话框 88 | mIatDialog.setListener(mRecognizerDialogListener); 89 | mIatDialog.show(); 90 | // showTip(this.getString(getId("text_begin","string"))); 91 | }else { 92 | // 不显示听写对话框 93 | ret = mIat.startListening(mRecognizerListener); 94 | if (ret != ErrorCode.SUCCESS) { 95 | // showTip("听写失败,错误码:" + ret); 96 | finishThisActivity(RESULT_CANCELED,"听写失败,错误码:" + ret); 97 | } else { 98 | // showTip(this.getString(getId("text_begin","string"))); 99 | } 100 | } 101 | 102 | 103 | } 104 | private int getId(String idName,String type){ 105 | return getResources().getIdentifier(idName, type,getPackageName()); 106 | } 107 | 108 | 109 | private void showTip(final String str) { 110 | mHandler.post(new Runnable() { 111 | @Override 112 | public void run() { 113 | mToast.setText(str); 114 | mToast.show(); 115 | } 116 | }); 117 | } 118 | 119 | int ret = 0; // 函数调用返回值 120 | /** 121 | * 听写UI监听器 122 | */ 123 | private RecognizerDialogListener mRecognizerDialogListener = new RecognizerDialogListener() { 124 | public void onResult(RecognizerResult results, boolean isLast) { 125 | printResult(results,isLast); 126 | } 127 | 128 | /** 129 | * 识别回调错误. 130 | */ 131 | public void onError(SpeechError error) { 132 | // showTip(error.getPlainDescription(true)); 133 | finishThisActivity(RESULT_CANCELED,error.getPlainDescription(true)); 134 | } 135 | }; 136 | 137 | private void finishThisActivity(int type ,String str){ 138 | Intent resultIntent = new Intent(); 139 | Bundle bundle = new Bundle(); 140 | bundle.putString("result", str); 141 | resultIntent.putExtras(bundle); 142 | setResult(type, resultIntent); 143 | finish(); 144 | } 145 | 146 | /** 147 | * 初始化监听器。 148 | */ 149 | private InitListener mInitListener = new InitListener() { 150 | 151 | @Override 152 | public void onInit(int code) { 153 | Log.d(TAG, "SpeechRecognizer init() code = " + code); 154 | if (code != ErrorCode.SUCCESS) { 155 | showTip("初始化失败,错误码:" + code); 156 | } 157 | } 158 | }; 159 | 160 | /** 161 | * 听写监听器。 162 | */ 163 | private RecognizerListener mRecognizerListener = new RecognizerListener() { 164 | 165 | @Override 166 | public void onBeginOfSpeech() { 167 | // 此回调表示:sdk内部录音机已经准备好了,用户可以开始语音输入 168 | // showTip("开始说话"); 169 | } 170 | 171 | @Override 172 | public void onError(SpeechError error) { 173 | // Tips: 174 | // 错误码:10118(您没有说话),可能是录音机权限被禁,需要提示用户打开应用的录音权限。 175 | // 如果使用本地功能(语记)需要提示用户开启语记的录音权限。 176 | // showTip(error.getPlainDescription(true)); 177 | finishThisActivity(RESULT_CANCELED,error.getPlainDescription(true)); 178 | } 179 | 180 | @Override 181 | public void onEndOfSpeech() { 182 | // 此回调表示:检测到了语音的尾端点,已经进入识别过程,不再接受语音输入 183 | // showTip("结束说话"); 184 | 185 | } 186 | 187 | @Override 188 | public void onResult(RecognizerResult results, boolean isLast) { 189 | Log.d(TAG, results.getResultString()); 190 | printResult(results,isLast); 191 | 192 | } 193 | 194 | 195 | @Override 196 | public void onVolumeChanged(int volume, byte[] data) { 197 | // showTip("当前正在说话,音量大小:" + volume); 198 | // showTip("当前正在说话..."); 199 | // Log.d(TAG, "返回音频数据:" + data.length); 200 | } 201 | 202 | @Override 203 | public void onEvent(int eventType, int arg1, int arg2, Bundle obj) { 204 | // 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因 205 | // 若使用本地能力,会话id为null 206 | // if (SpeechEvent.EVENT_SESSION_ID == eventType) { 207 | // String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID); 208 | // Log.d(TAG, "session id =" + sid); 209 | // } 210 | 211 | } 212 | }; 213 | 214 | private void printResult(RecognizerResult results,boolean isLast) { 215 | String text = JsonParser.parseIatResult(results.getResultString()); 216 | String sn = null; 217 | // 读取json结果中的sn字段 218 | try { 219 | JSONObject resultJson = new JSONObject(results.getResultString()); 220 | sn = resultJson.optString("sn"); 221 | } catch (JSONException e) { 222 | e.printStackTrace(); 223 | } 224 | mIatResults.put(sn, text); 225 | StringBuffer resultBuffer = new StringBuffer(); 226 | for (String key : mIatResults.keySet()) { 227 | resultBuffer.append(mIatResults.get(key)); 228 | } 229 | Log.d(TAG, "音频中文:" + resultBuffer.toString()); 230 | // mResultText.setText(resultBuffer.toString()); 231 | // mResultText.setSelection(mResultText.length()); 232 | if (isLast){ 233 | Intent resultIntent = new Intent(); 234 | Bundle bundle = new Bundle(); 235 | bundle.putString("result", resultBuffer.toString()); 236 | resultIntent.putExtras(bundle); 237 | this.setResult(RESULT_OK, resultIntent); 238 | finish(); 239 | } 240 | 241 | } 242 | 243 | /** 244 | * 参数设置 245 | * 246 | * @param 247 | * @return 248 | */ 249 | public void setParam() { 250 | // 清空参数 251 | mIat.setParameter(SpeechConstant.PARAMS, null); 252 | 253 | // 设置听写引擎 254 | mIat.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType); 255 | // 设置返回结果格式 256 | mIat.setParameter(SpeechConstant.RESULT_TYPE, "json"); 257 | 258 | String lag = mSharedPreferences.getString("iat_language_preference", 259 | "mandarin"); 260 | if (lag.equals("en_us")) { 261 | // 设置语言 262 | mIat.setParameter(SpeechConstant.LANGUAGE, "en_us"); 263 | } else { 264 | // 设置语言 265 | mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn"); 266 | // 设置语言区域 267 | mIat.setParameter(SpeechConstant.ACCENT, lag); 268 | } 269 | 270 | // 设置语音前端点:静音超时时间,即用户多长时间不说话则当做超时处理 271 | mIat.setParameter(SpeechConstant.VAD_BOS, mSharedPreferences.getString("iat_vadbos_preference", "4000")); 272 | 273 | // 设置语音后端点:后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 自动停止录音 274 | mIat.setParameter(SpeechConstant.VAD_EOS, mSharedPreferences.getString("iat_vadeos_preference", "1000")); 275 | 276 | // 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点 277 | // mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", "1")); 278 | // mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", punc)); 279 | mIat.setParameter(SpeechConstant.ASR_PTT, punc); 280 | 281 | // 设置听写结果是否结果动态修正,为“1”则在听写过程中动态递增地返回结果,否则只在听写结束之后返回最终结果 282 | // 注:该参数暂时只对在线听写有效 283 | // mIat.setParameter(SpeechConstant.ASR_DWA, mSharedPreferences.getString("iat_dwa_preference", "0")); 284 | 285 | // 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限 286 | // 注:AUDIO_FORMAT参数语记需要更新版本才能生效 287 | mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "wav"); 288 | mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory() + "/msc/iat.wav"); 289 | } 290 | 291 | 292 | @Override 293 | protected void onDestroy() { 294 | super.onDestroy(); 295 | if (mIatDialog.isShowing()){ 296 | mIatDialog.dismiss(); 297 | } 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /src/android/src/com/thomas/xunfeilistenspeaking/XunfeiListenSpeaking.java: -------------------------------------------------------------------------------- 1 | package com.thomas.xunfeilistenspeaking; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.os.Bundle; 8 | import android.os.Environment; 9 | import android.os.Handler; 10 | import android.util.Log; 11 | import android.widget.Toast; 12 | import com.iflytek.cloud.*; 13 | import com.iflytek.sunflower.FlowerCollector; 14 | import org.apache.cordova.CallbackContext; 15 | import org.apache.cordova.CordovaPlugin; 16 | import org.json.JSONArray; 17 | import org.json.JSONException; 18 | import org.json.JSONObject; 19 | 20 | import java.util.HashMap; 21 | import java.util.LinkedHashMap; 22 | 23 | /** 24 | * Created by Thomas.Wang on 17/2/9. 25 | */ 26 | public class XunfeiListenSpeaking extends CordovaPlugin{ 27 | private static String TAG = XunfeiListenSpeaking.class.getSimpleName(); 28 | private Context context; 29 | private CallbackContext callbackContext; 30 | private Toast mToast; 31 | private Handler mHandler = new Handler(); 32 | 33 | private SpeechSynthesizer mTts; 34 | 35 | // 语音听写对象 36 | private SpeechRecognizer mIat; 37 | 38 | private SharedPreferences mSharedPreferences; 39 | // 引擎类型 40 | private String mEngineType = SpeechConstant.TYPE_CLOUD; 41 | // 用HashMap存储听写结果 42 | private HashMap mIatResults = new LinkedHashMap(); 43 | @Override 44 | protected void pluginInitialize() { 45 | super.pluginInitialize(); 46 | context = cordova.getActivity(); 47 | // SpeechUtility.createUtility(context, SpeechConstant.APPID +"=584e7225"); 48 | SpeechUtility.createUtility(context, SpeechConstant.APPID +"="+context.getString(getId("app_id","string"))); 49 | } 50 | 51 | private int getId(String idName,String type){ 52 | return context.getResources().getIdentifier(idName, type,context.getPackageName()); 53 | } 54 | private static final int DIALOG_ACTIVIT_CODE = 0; 55 | @Override 56 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 57 | 58 | this.callbackContext = callbackContext; 59 | //开始听写 60 | if (action.equals("startListen")){ 61 | // boolean isShowDialog = args.getBoolean(0); 62 | 63 | // String punc = args.getBoolean(1)?"1":"0"; 64 | boolean isShowDialog ; 65 | try { 66 | isShowDialog = args.getBoolean(0); 67 | }catch (Exception e){ 68 | isShowDialog = true; 69 | } 70 | String punc; 71 | try{ 72 | punc = args.getBoolean(1)?"1":"0"; 73 | }catch (Exception e){ 74 | punc = "1"; 75 | } 76 | if (isShowDialog){ 77 | Intent intent = new Intent(); 78 | intent.setClass(context, XunfeiDialogActivity.class); 79 | intent.putExtra("isShowDialog",isShowDialog); 80 | intent.putExtra("punc",punc); 81 | cordova.startActivityForResult( this,intent, DIALOG_ACTIVIT_CODE); 82 | }else { 83 | startListenWidthNotDialog(punc); 84 | } 85 | 86 | 87 | return true; 88 | } 89 | 90 | //停止听写 91 | if (action.equals("stopListen")) { 92 | stopListen(); 93 | return true; 94 | } 95 | 96 | 97 | //开始听写 98 | if (action.equals("startSpeak")){ 99 | mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); 100 | String speakMessage = args.getString(0).trim(); 101 | startSpeak(speakMessage); 102 | return true; 103 | } 104 | //停止说话 105 | if (action.equals("stopSpeak")){ 106 | stopSpeak(); 107 | return true; 108 | } 109 | 110 | //暂停 111 | if (action.equals("pauseSpeaking")){ 112 | pauseSpeaking(); 113 | return true; 114 | } 115 | //继续 116 | if (action.equals("resumeSpeaking")){ 117 | resumeSpeaking(); 118 | return true; 119 | } 120 | 121 | return false; 122 | } 123 | 124 | 125 | private void stopListen(){ 126 | if (mIat!=null&&mIat.isListening()) { 127 | mIat.stopListening(); 128 | } 129 | } 130 | int ret = 0; // 函数调用返回值 131 | private void startListenWidthNotDialog(String punc){ 132 | mIat = SpeechRecognizer.createRecognizer(context, mInitListener); 133 | mSharedPreferences = context.getSharedPreferences(IatSettings.PREFER_NAME, 134 | Activity.MODE_PRIVATE); 135 | if (mIat.isListening()) { 136 | mIat.stopListening(); 137 | } 138 | // 移动数据分析,收集开始听写事件 139 | FlowerCollector.onEvent(context, "iat_recognize"); 140 | mIatResults.clear(); 141 | // 设置参数 142 | setParam(punc); 143 | 144 | 145 | // 不显示听写对话框 146 | ret = mIat.startListening(mRecognizerListener); 147 | if (ret != ErrorCode.SUCCESS) { 148 | // showTip("听写失败,错误码:" + ret); 149 | // finishThisActivity(RESULT_CANCELED,"听写失败,错误码:" + ret); 150 | callbackContext.error("听写失败,错误码:" + ret); 151 | 152 | } else { 153 | // showTip(this.getString(getId("text_begin","string"))); 154 | } 155 | 156 | 157 | 158 | } 159 | 160 | /** 161 | * 初始化监听器。 162 | */ 163 | private InitListener mInitListener = new InitListener() { 164 | 165 | @Override 166 | public void onInit(int code) { 167 | Log.d(TAG, "SpeechRecognizer init() code = " + code); 168 | if (code != ErrorCode.SUCCESS) { 169 | showTip("初始化失败,错误码:" + code); 170 | } 171 | } 172 | }; 173 | 174 | /** 175 | * 听写监听器。 176 | */ 177 | private RecognizerListener mRecognizerListener = new RecognizerListener() { 178 | 179 | @Override 180 | public void onBeginOfSpeech() { 181 | // 此回调表示:sdk内部录音机已经准备好了,用户可以开始语音输入 182 | // showTip("开始说话"); 183 | } 184 | 185 | @Override 186 | public void onError(SpeechError error) { 187 | // Tips: 188 | // 错误码:10118(您没有说话),可能是录音机权限被禁,需要提示用户打开应用的录音权限。 189 | // 如果使用本地功能(语记)需要提示用户开启语记的录音权限。 190 | // showTip(error.getPlainDescription(true)); 191 | // finishThisActivity(RESULT_CANCELED,error.getPlainDescription(true)); 192 | callbackContext.error(error.getPlainDescription(true)); 193 | } 194 | 195 | @Override 196 | public void onEndOfSpeech() { 197 | // 此回调表示:检测到了语音的尾端点,已经进入识别过程,不再接受语音输入 198 | // showTip("结束说话"); 199 | 200 | } 201 | 202 | @Override 203 | public void onResult(RecognizerResult results, boolean isLast) { 204 | Log.d(TAG, results.getResultString()); 205 | 206 | printResult(results,isLast); 207 | 208 | } 209 | 210 | 211 | @Override 212 | public void onVolumeChanged(int volume, byte[] data) { 213 | // showTip("当前正在说话,音量大小:" + volume); 214 | // showTip("当前正在说话..."); 215 | // Log.d(TAG, "返回音频数据:" + data.length); 216 | } 217 | 218 | @Override 219 | public void onEvent(int eventType, int arg1, int arg2, Bundle obj) { 220 | // 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因 221 | // 若使用本地能力,会话id为null 222 | // if (SpeechEvent.EVENT_SESSION_ID == eventType) { 223 | // String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID); 224 | // Log.d(TAG, "session id =" + sid); 225 | // } 226 | 227 | } 228 | }; 229 | 230 | private void printResult(RecognizerResult results, boolean isLast) { 231 | String text = JsonParser.parseIatResult(results.getResultString()); 232 | String sn = null; 233 | // 读取json结果中的sn字段 234 | try { 235 | JSONObject resultJson = new JSONObject(results.getResultString()); 236 | sn = resultJson.optString("sn"); 237 | } catch (JSONException e) { 238 | e.printStackTrace(); 239 | } 240 | mIatResults.put(sn, text); 241 | StringBuffer resultBuffer = new StringBuffer(); 242 | for (String key : mIatResults.keySet()) { 243 | resultBuffer.append(mIatResults.get(key)); 244 | } 245 | Log.d(TAG, "音频中文:" + resultBuffer.toString()); 246 | // mResultText.setText(resultBuffer.toString()); 247 | // mResultText.setSelection(mResultText.length()); 248 | // Intent resultIntent = new Intent(); 249 | // Bundle bundle = new Bundle(); 250 | // bundle.putString("result", resultBuffer.toString()); 251 | // resultIntent.putExtras(bundle); 252 | // this.setResult(RESULT_OK, resultIntent); 253 | // finish(); 254 | if (isLast) 255 | callbackContext.success(resultBuffer.toString()); 256 | } 257 | 258 | /** 259 | * 参数设置 260 | * 261 | * @param 262 | * @return 263 | */ 264 | public void setParam(String punc) { 265 | // 清空参数 266 | mIat.setParameter(SpeechConstant.PARAMS, null); 267 | 268 | // 设置听写引擎 269 | mIat.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType); 270 | // 设置返回结果格式 271 | mIat.setParameter(SpeechConstant.RESULT_TYPE, "json"); 272 | 273 | String lag = mSharedPreferences.getString("iat_language_preference", 274 | "mandarin"); 275 | if (lag.equals("en_us")) { 276 | // 设置语言 277 | mIat.setParameter(SpeechConstant.LANGUAGE, "en_us"); 278 | } else { 279 | // 设置语言 280 | mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn"); 281 | // 设置语言区域 282 | mIat.setParameter(SpeechConstant.ACCENT, lag); 283 | } 284 | 285 | // 设置语音前端点:静音超时时间,即用户多长时间不说话则当做超时处理 286 | mIat.setParameter(SpeechConstant.VAD_BOS, mSharedPreferences.getString("iat_vadbos_preference", "4000")); 287 | 288 | // 设置语音后端点:后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 自动停止录音 289 | mIat.setParameter(SpeechConstant.VAD_EOS, mSharedPreferences.getString("iat_vadeos_preference", "1000")); 290 | 291 | // 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点 292 | // mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", "1")); 293 | // mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", punc)); 294 | mIat.setParameter(SpeechConstant.ASR_PTT, punc); 295 | 296 | // 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限 297 | // 注:AUDIO_FORMAT参数语记需要更新版本才能生效 298 | mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "wav"); 299 | mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory() + "/msc/iat.wav"); 300 | } 301 | 302 | 303 | private void resumeSpeaking(){ 304 | mTts.resumeSpeaking(); 305 | } 306 | private void pauseSpeaking(){ 307 | mTts.pauseSpeaking(); 308 | } 309 | 310 | private void stopSpeak(){ 311 | if(mTts!=null&&mTts.isSpeaking()){ 312 | mTts.stopSpeaking(); 313 | } 314 | } 315 | 316 | private void startSpeak(String speakMessage) { 317 | setSpeakParameter(); 318 | if (mTts.isSpeaking()){ 319 | mTts.stopSpeaking(); 320 | } 321 | mTts.startSpeaking(speakMessage, mSynListener); 322 | 323 | } 324 | 325 | private void setSpeakParameter(){ 326 | if (mTts==null){ 327 | //1.创建SpeechSynthesizer对象, 第二个参数:本地合成时传InitListener 328 | mTts = SpeechSynthesizer.createSynthesizer(context, null); 329 | //2.合成参数设置,详见《科大讯飞MSC API手册(Android)》SpeechSynthesizer 类 330 | mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan");//设置发音人 331 | mTts.setParameter(SpeechConstant.SPEED, "50");//设置语速 332 | mTts.setParameter(SpeechConstant.VOLUME, "80");//设置音量,范围0~100 333 | mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); //设置云端 334 | //设置合成音频保存位置(可自定义保存位置),保存在“./sdcard/iflytek.pcm” 335 | //保存在SD卡需要在AndroidManifest.xml添加写SD卡权限 336 | //如果不需要保存合成音频,注释该行代码 337 | mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, "./sdcard/iflytek.pcm"); 338 | //3.开始合成 339 | // mTts.startSpeaking("科大讯飞,让世界聆听我们的声音", mSynListener); 340 | } 341 | } 342 | //合成监听器 343 | private SynthesizerListener mSynListener = new SynthesizerListener(){ 344 | //会话结束回调接口,没有错误时,error为null 345 | public void onCompleted(SpeechError error) { 346 | if (error == null) { 347 | // showTip("播放完成"); 348 | callbackContext.success("播放完成"); 349 | } else if (error != null) { 350 | showTip(error.getPlainDescription(true)); 351 | callbackContext.error(error.getPlainDescription(true)); 352 | } 353 | } 354 | //缓冲进度回调 355 | //percent为缓冲进度0~100,beginPos为缓冲音频在文本中开始位置,endPos表示缓冲音频在文本中结束位置,info为附加信息。 356 | public void onBufferProgress(int percent, int beginPos, int endPos, String info) {} 357 | //开始播放 358 | public void onSpeakBegin() { 359 | 360 | // showTip("开始播放"); 361 | } 362 | //暂停播放 363 | public void onSpeakPaused() {} 364 | //播放进度回调 365 | //percent为播放进度0~100,beginPos为播放音频在文本中开始位置,endPos表示播放音频在文本中结束位置. 366 | public void onSpeakProgress(int percent, int beginPos, int endPos) {} 367 | //恢复播放回调接口 368 | public void onSpeakResumed() {} 369 | //会话事件回调接口 370 | public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) {} 371 | }; 372 | 373 | @Override 374 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 375 | super.onActivityResult(requestCode, resultCode, data); 376 | switch (requestCode) { 377 | case DIALOG_ACTIVIT_CODE: 378 | if(resultCode == Activity.RESULT_OK){ 379 | Bundle bundle = data.getExtras(); 380 | callbackContext.success(bundle.getString("result")); 381 | }else if (resultCode == Activity.RESULT_CANCELED){ 382 | Bundle bundle = data.getExtras(); 383 | callbackContext.error(bundle.getString("result")); 384 | } 385 | break; 386 | } 387 | } 388 | private void showTip(final String str) { 389 | mHandler.post(new Runnable() { 390 | @Override 391 | public void run() { 392 | mToast.setText(str); 393 | mToast.show(); 394 | } 395 | }); 396 | } 397 | 398 | 399 | } 400 | -------------------------------------------------------------------------------- /src/ios/CDVSpeech.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDVSpeech.h 3 | // ZJxunfeiDemo-OC 4 | // 5 | // Created by Edc.zhang on 2017/2/13. 6 | // Copyright © 2017年 Edc.zhang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import 12 | 13 | //#import "iflyMSC/iflyMSC.h" 14 | #import "iflyMSC.framework/Headers/IFlyMSC.h" 15 | 16 | 17 | @interface CDVSpeech : CDVPlugin { 18 | 19 | } 20 | @property (nonatomic, copy) NSString* appId; 21 | @property (nonatomic, strong) NSString* callbackId; 22 | @property (nonatomic, strong) IFlySpeechRecognizer* recognizer; 23 | @property (nonatomic, strong) IFlySpeechSynthesizer* synthesizer; 24 | @property(nonatomic,strong) IFlyRecognizerView *iflyRecognizerView; 25 | 26 | 27 | - (void)startListening:(CDVInvokedUrlCommand*)command; 28 | - (void)stopListening:(CDVInvokedUrlCommand*)command; 29 | - (void)cancelListening:(CDVInvokedUrlCommand*)command; 30 | 31 | - (void)startSpeaking:(CDVInvokedUrlCommand*)command; 32 | - (void)pauseSpeaking:(CDVInvokedUrlCommand*)command; 33 | - (void)resumeSpeaking:(CDVInvokedUrlCommand*)command; 34 | - (void)stopSpeaking:(CDVInvokedUrlCommand*)command; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /src/ios/CDVSpeech.m: -------------------------------------------------------------------------------- 1 | // 2 | // CDVSpeech.m 3 | // ZJxunfeiDemo-OC 4 | // 5 | // Created by Edc.zhang on 2017/2/13. 6 | // Copyright © 2017年 Edc.zhang. All rights reserved. 7 | // 8 | 9 | 10 | #import "CDVSpeech.h" 11 | 12 | #define STR_EVENT @"event" 13 | #define STR_CODE @"code" 14 | #define STR_MESSAGE @"message" 15 | #define STR_VOLUME @"volume" 16 | #define STR_RESULTS @"results" 17 | #define STR_PROGRESS @"progress" 18 | 19 | // always replace the appid and the SDK with what you get from voicecloud.cn 20 | #define SPEECH_APP_ID @"589d270d" 21 | 22 | 23 | @interface CDVSpeech() 24 | - (void) fireEvent:(NSString*)event; 25 | @end 26 | 27 | #import "CDVSpeech.h" 28 | 29 | @implementation CDVSpeech 30 | - (void)login:(CDVInvokedUrlCommand*)command 31 | { 32 | self.callbackId = command.callbackId; 33 | 34 | self.appId = SPEECH_APP_ID; 35 | 36 | NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",self.appId]; 37 | [IFlySpeechUtility createUtility:initString]; 38 | 39 | } 40 | 41 | #pragma mark - 语音录入 42 | - (void)startListening:(CDVInvokedUrlCommand*)command 43 | { 44 | NSLog(@"Speech :: startListening"); 45 | NSDictionary* options = [command.arguments objectAtIndex:0]; 46 | // withDefault:[NSNull null]]; 47 | //是否有UI弹窗 48 | // BOOL isShowDialog = [command.arguments objectAtIndex:1]; 49 | NSString *isShowDialog = [NSString stringWithFormat:@"%@",[command.arguments objectAtIndex:1]]; 50 | NSString *isShowPunc = [NSString stringWithFormat:@"%@",[command.arguments objectAtIndex:2]]; 51 | if ([isShowDialog isEqualToString:@"0"]) { 52 | if (!self.recognizer){ 53 | self.recognizer = [IFlySpeechRecognizer sharedInstance]; 54 | self.recognizer.delegate = self; 55 | [self.recognizer setParameter:@"iat" forKey:@"domain"]; 56 | [self.recognizer setParameter:@"16000" forKey:@"sample_rate"]; 57 | [self.recognizer setParameter:@"700" forKey:@"vad_eos"]; 58 | [self.recognizer setParameter:@"0" forKey:@"plain_result"]; 59 | [self.recognizer setParameter:@"asr.pcm" forKey:@"asr_audio_path"]; 60 | //是否显示标点 61 | if ([isShowPunc isEqualToString:@"0"]) { 62 | [self.recognizer setParameter:@"0" forKey:@"asr_ptt"]; 63 | } 64 | NSLog(@"Speech :: createRecognizer"); 65 | } 66 | if ((NSNull *)options != [NSNull null]) { 67 | NSArray *keys = [options allKeys]; 68 | for (NSString *key in keys) { 69 | NSString *value = [options objectForKey:key]; 70 | [self.recognizer setParameter:value forKey:key]; 71 | } 72 | } 73 | 74 | //判断当前是否正在听 若正在识别则先停止 再开始听 75 | if ([self.recognizer isListening]) { 76 | [self.recognizer stopListening]; 77 | } 78 | [self.recognizer startListening]; 79 | 80 | }else{ 81 | //初始化语音识别控件 82 | UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; 83 | self.iflyRecognizerView = [[IFlyRecognizerView alloc] initWithCenter:keyWindow.center]; 84 | self.iflyRecognizerView.delegate = self; 85 | [self.iflyRecognizerView setParameter: @"iat" forKey: [IFlySpeechConstant IFLY_DOMAIN]]; 86 | //asr_audio_path保存录音文件名,如不再需要,设置value为nil表示取消,默认目录是documents 87 | [self.iflyRecognizerView setParameter:@"asrview.pcm " forKey:[IFlySpeechConstant ASR_AUDIO_PATH]]; 88 | if ([isShowPunc isEqualToString:@"0"]) { 89 | [self.iflyRecognizerView setParameter:@"0" forKey:@"asr_ptt"]; 90 | } 91 | [self.iflyRecognizerView start]; 92 | } 93 | } 94 | 95 | - (void)stopListening:(CDVInvokedUrlCommand*)command 96 | { 97 | NSLog(@"Speech :: stopListening"); 98 | [self.recognizer stopListening]; 99 | } 100 | 101 | - (void)cancelListening:(CDVInvokedUrlCommand*)command 102 | { 103 | NSLog(@"Speech :: cancelListening"); 104 | [self.recognizer cancel]; 105 | [self.iflyRecognizerView cancel]; 106 | } 107 | 108 | 109 | #pragma mark - 语音朗读 110 | - (void)startSpeaking:(CDVInvokedUrlCommand*)command 111 | { 112 | NSString* text = [command.arguments objectAtIndex:0]; 113 | NSDictionary* options = [command.arguments objectAtIndex:1]; 114 | // withDefault:[NSNull null]]; 115 | NSLog(@"Speech :: startSpeaking - %@", text); 116 | // [self.commandDelegate runInBackground:^{ 117 | if (!self.synthesizer){ 118 | self.synthesizer = [IFlySpeechSynthesizer sharedInstance]; 119 | self.synthesizer.delegate = self; 120 | 121 | [self.synthesizer setParameter:@"50" forKey:[IFlySpeechConstant SPEED]];//合成的语速,取值范围 0~100 122 | [self.synthesizer setParameter:@"80" forKey:[IFlySpeechConstant VOLUME]];//合成的音量;取值范围 0~100 123 | [self.synthesizer setParameter:@"vixr" forKey:[IFlySpeechConstant VOICE_NAME]];//发音人,默认为”xiaoyan” 124 | 125 | [self.synthesizer setParameter:@"8000" forKey: [IFlySpeechConstant SAMPLE_RATE]];//音频采样率,目前支持的采样率有 16000 和 8000; 126 | [self.synthesizer setParameter:@"tts.pcm" forKey: [IFlySpeechConstant TTS_AUDIO_PATH]]; 127 | 128 | NSLog(@"Speech :: createSynthesizer"); 129 | } 130 | if ((NSNull *)options != [NSNull null]) { 131 | NSArray *keys = [options allKeys]; 132 | for (NSString *key in keys) { 133 | NSString *value = [options objectForKey:key]; 134 | [self.synthesizer setParameter:value forKey:key]; 135 | } 136 | } 137 | 138 | if ([self.synthesizer isSpeaking]) { 139 | [self.synthesizer stopSpeaking]; 140 | } 141 | [self.synthesizer startSpeaking:text]; 142 | // }]; 143 | } 144 | 145 | #pragma mark - 暂停语音朗读 146 | - (void)pauseSpeaking:(CDVInvokedUrlCommand*)command 147 | { 148 | NSLog(@"Speech :: pauseSpeaking"); 149 | [self.synthesizer pauseSpeaking]; 150 | } 151 | 152 | #pragma mark - 继续语音朗读 153 | - (void)resumeSpeaking:(CDVInvokedUrlCommand*)command 154 | { 155 | NSLog(@"Speech :: resumeSpeaking"); 156 | [self.synthesizer resumeSpeaking]; 157 | } 158 | 159 | #pragma mark - 停止语音朗读 160 | - (void)stopSpeaking:(CDVInvokedUrlCommand*)command 161 | { 162 | NSLog(@"Speech :: stopSpeaking"); 163 | [self.synthesizer stopSpeaking]; 164 | } 165 | 166 | 167 | #pragma mark IFlyRecognizerViewDelegate 168 | 169 | /*! 有UI 170 | * IFlyRecognizerViewDelegate 回调返回识别结果 171 | * 172 | * @param resultArray 识别结果,NSArray的第一个元素为NSDictionary,NSDictionary的key为识别结果,sc为识别结果的置信度 173 | * @param isLast -[out] 是否最后一个结果 174 | */ 175 | - (void)onResult:(NSArray *)resultArray isLast:(BOOL) isLast{ 176 | 177 | NSLog(@"Speech :: onResults - %@", resultArray); 178 | if (self.callbackId) { 179 | NSMutableString *text = [[NSMutableString alloc] init]; 180 | NSDictionary *dic = [resultArray objectAtIndex:0]; 181 | for (NSString *key in dic) { 182 | [text appendFormat:@"%@",key]; 183 | } 184 | NSLog(@"Recognize Result: %@",text); 185 | 186 | // NSString * resultFromJson = [ISRDataHelper stringFromJson:text]; 187 | // 188 | // NSLog(@"---------%@",resultFromJson); 189 | 190 | NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:@"SpeechResults",STR_EVENT,text,STR_RESULTS, nil]; 191 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 192 | [result setKeepCallbackAsBool:YES]; 193 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 194 | } 195 | } 196 | 197 | 198 | /*! 无UI 199 | * IFlySpeechRecognizerDelegate 识别结果回调 200 | * 在识别过程中可能会多次回调此函数,你最好不要在此回调函数中进行界面的更改等操作,只需要将回调的结果保存起来。 201 | * 使用results的示例如下: 202 | *

203 |  *  - (void) onResults:(NSArray *) results{
204 |  *     NSMutableString *result = [[NSMutableString alloc] init];
205 |  *     NSDictionary *dic = [results objectAtIndex:0];
206 |  *     for (NSString *key in dic){
207 |  *        [result appendFormat:@"%@",key];//合并结果
208 |  *     }
209 |  *   }
210 |  *  
211 | * 212 | * @param results -[out] 识别结果,NSArray的第一个元素为NSDictionary,NSDictionary的key为识别结果,sc为识别结果的置信度。 213 | * @param isLast -[out] 是否最后一个结果 214 | */ 215 | - (void) onResults:(NSArray *) results isLast:(BOOL)isLast{ 216 | NSLog(@"Speech :: onResults - %@", results); 217 | if (self.callbackId) { 218 | NSMutableString *text = [[NSMutableString alloc] init]; 219 | NSDictionary *dic = [results objectAtIndex:0]; 220 | for (NSString *key in dic) { 221 | [text appendFormat:@"%@",key]; 222 | } 223 | NSLog(@"Recognize Result: %@",text); 224 | 225 | // NSString * resultFromJson = [ISRDataHelper stringFromJson:text]; 226 | // 227 | // NSLog(@"---------%@",resultFromJson); 228 | 229 | NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:@"SpeechResults",STR_EVENT,text,STR_RESULTS, nil]; 230 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 231 | [result setKeepCallbackAsBool:YES]; 232 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 233 | } 234 | } 235 | 236 | /*! 237 | * IFlySpeechRecognizerDelegate 音量变化回调 238 | * 在录音过程中,回调音频的音量。 239 | * 240 | * @param volume -[out] 音量,范围从0-30 241 | */ 242 | 243 | - (void) onVolumeChanged:(int)volume 244 | { 245 | NSLog(@"Speech :: onVolumeChanged - %d", volume); 246 | if (self.callbackId) { 247 | NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:@"VolumeChanged",STR_EVENT,[NSNumber numberWithInt:volume],STR_VOLUME, nil]; 248 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 249 | [result setKeepCallbackAsBool:YES]; 250 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 251 | } 252 | } 253 | 254 | 255 | /*! 256 | * 识别结束回调 257 | * 258 | * @param error 识别结束错误码 259 | */ 260 | - (void)onError: (IFlySpeechError *) error{ 261 | NSLog(@"Speech :: onError - %d", error.errorCode); 262 | if (self.callbackId) { 263 | NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:@"11SpeechError",STR_EVENT,[NSNumber numberWithInt:error.errorCode],STR_CODE,error.errorDesc,STR_MESSAGE, nil]; 264 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 265 | [result setKeepCallbackAsBool:YES]; 266 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 267 | } 268 | } 269 | 270 | 271 | #pragma mark IFlySpeechSynthesizerDelegate 272 | - (void) onCompleted:(IFlySpeechError*)error 273 | { 274 | NSLog(@"Speech :: onCompleted - %d", error.errorCode); 275 | if (self.callbackId) { 276 | NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:@"SpeakCompleted",STR_EVENT,[NSNumber numberWithInt:error.errorCode],STR_CODE,error.errorDesc,STR_MESSAGE, nil]; 277 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 278 | [result setKeepCallbackAsBool:YES]; 279 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 280 | } 281 | } 282 | 283 | - (void) onSpeakBegin 284 | { 285 | NSLog(@"Speech :: onSpeakBegin"); 286 | [self fireEvent:@"SpeakBegin"]; 287 | } 288 | 289 | - (void) onBufferProgress:(int)progress message:(NSString *)msg 290 | { 291 | NSLog(@"Speech :: onBufferProgress - %d", progress); 292 | if (self.callbackId) { 293 | NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:@"BufferProgress",STR_EVENT,[NSNumber numberWithInt:progress],STR_PROGRESS,msg,STR_MESSAGE, nil]; 294 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 295 | [result setKeepCallbackAsBool:YES]; 296 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 297 | } 298 | } 299 | 300 | - (void) onSpeakProgress:(int)progress 301 | { 302 | NSLog(@"Speech :: onSpeakProgress - %d", progress); 303 | if (self.callbackId) { 304 | NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:@"SpeakProgress",STR_EVENT,[NSNumber numberWithInt:progress],STR_PROGRESS, nil]; 305 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 306 | [result setKeepCallbackAsBool:YES]; 307 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 308 | } 309 | } 310 | 311 | - (void) onSpeakPaused 312 | { 313 | NSLog(@"Speech :: onSpeakPaused"); 314 | [self fireEvent:@"SpeakPaused"]; 315 | } 316 | 317 | - (void) onSpeakResumed 318 | { 319 | NSLog(@"Speech :: onSpeakResumed"); 320 | [self fireEvent:@"SpeakResumed"]; 321 | } 322 | 323 | - (void) onSpeakCancel 324 | { 325 | NSLog(@"Speech :: onSpeakCancel"); 326 | [self fireEvent:@"SpeakCancel"]; 327 | } 328 | 329 | - (void) fireEvent:(NSString*)event 330 | { 331 | if (self.callbackId) { 332 | NSDictionary* info = [NSDictionary dictionaryWithObject:event forKey:STR_EVENT]; 333 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; 334 | [result setKeepCallbackAsBool:YES]; 335 | [self.commandDelegate sendPluginResult:result callbackId:self.callbackId]; 336 | } 337 | } 338 | 339 | 340 | 341 | 342 | 343 | @end 344 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyContact.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyContact.h 3 | // msc 4 | // 5 | // Created by ypzhao on 13-3-1. 6 | // Copyright (c) 2013年 IFLYTEK. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! 12 | * 此接口为获取通信录中的联系人 13 | * 获取联系人是为了在进行语音识别时(sms)能更好的识别出您说的人名,联系人上传是属于个性化的 14 | * 一部分. 15 | */ 16 | @interface IFlyContact : NSObject 17 | 18 | /*! 19 | * 获取联系人 20 | * 调用此方法需要添加 AddressBook.framework 到工程中,调用此方法后可以直接将通信录中的联系 21 | * 人转化为语音云识别的数据结构。您可以将获取的数据通过IFlyDataUploader类,上传到语音云,我们 22 | * 只获取通信录中的人名 23 | * 24 | * @return 返回联系人信息 25 | */ 26 | - (NSString *) contact; 27 | @end 28 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyDataUploader.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyDataUploader.h 3 | // MSC 4 | // 5 | // Created by ypzhao on 13-4-8. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @class IFlySpeechError; 13 | 14 | /*! 15 | * 数据上传类 16 | */ 17 | @interface IFlyDataUploader : NSObject 18 | 19 | /*! 20 | * 数据名称 21 | */ 22 | @property(nonatomic,copy) NSString *dataName; 23 | /*! 24 | * 数据 25 | */ 26 | @property(nonatomic,copy) NSString *data; 27 | 28 | /*! 29 | * 上传完成回调 30 | * 31 | * @param result 结果 32 | * @param error 错误码 33 | */ 34 | typedef void(^IFlyUploadDataCompletionHandler)(NSString* result,IFlySpeechError * error); 35 | 36 | /*! 37 | * 上传数据 38 | * 此函数用于上传数据,下载的过程是**异步**的。 39 | * 40 | * @param completionHandler -[in] 上传完成回调 41 | * @param name -[in] 上传的内容名称,名称最好和你要上传的数据内容相关,不可以为nil 42 | * @param data -[in] 上传的数据,以utf8编码,不可以为nil 43 | */ 44 | - (void) uploadDataWithCompletionHandler:(IFlyUploadDataCompletionHandler)completionHandler name:(NSString *)name data:(NSString *)data; 45 | 46 | /*! 47 | * 设置上传数据参数 48 | * 49 | * @param parameter 参数值 50 | * @param key 参数名 51 | */ 52 | -(void) setParameter:(NSString*) parameter forKey:(NSString*) key; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyDebugLog.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyDebugLog.h 3 | // MSC 4 | 5 | // description: 程序中的log处理类 6 | 7 | // Created by ypzhao on 12-11-22. 8 | // Copyright (c) 2012年 iflytek. All rights reserved. 9 | // 10 | 11 | #import 12 | 13 | /*! 14 | * 调试信息 15 | */ 16 | @interface IFlyDebugLog : NSObject 17 | 18 | /*! 19 | * 打印调试信息 20 | * 21 | * @param format -[in] 要打印的内容格式 22 | * @param ... -[in] 要打印的内容 23 | */ 24 | + (void) showLog:(NSString *)format, ...; 25 | 26 | /*! 27 | * 将log写入文件中 28 | */ 29 | + (void) writeLog; 30 | 31 | /*! 32 | * 设置是否显示log 33 | * 34 | * @param showLog YES:显示;NO:不显示 35 | */ 36 | + (void) setShowLog:(BOOL) showLog; 37 | @end 38 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyISVDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyISVDelegate.h 3 | // msc_UI 4 | // 5 | // Created by admin on 14-9-15. 6 | // Copyright (c) 2014年 iflytek. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | 12 | @class IFlySpeechError; 13 | 14 | /** 15 | * 声纹回调协议 16 | */ 17 | @protocol IFlyISVDelegate 18 | 19 | /** 20 | * 声纹结果回调 21 | * 22 | * @param dic 结果 23 | */ 24 | -(void) onResult:(NSDictionary *)dic; 25 | 26 | /** 27 | * 错误码回调 28 | * 29 | * @param errorCode 错误码 30 | */ 31 | -(void) onError:(IFlySpeechError *) errorCode; 32 | 33 | @optional 34 | 35 | /** 36 | * 等待结果 37 | */ 38 | -(void) onRecognition; 39 | 40 | /** 41 | * 音量改变回调 42 | * 43 | * @param volume 音量值 44 | */ 45 | -(void) onVolumeChanged: (int)volume; 46 | 47 | @end 48 | 49 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyISVRecognizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyISVRecognizer.h 3 | // ISV 4 | // 5 | // Created by wangdan on 14-9-6. 6 | // Copyright (c) 2014年 IFlyTEK. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | #import "IFlyISVDelegate.h" 12 | 13 | /** 14 | * 声纹接口类 15 | */ 16 | @interface IFlyISVRecognizer : NSObject 17 | { 18 | 19 | } 20 | @property (assign) id delegate; 21 | 22 | 23 | 24 | /* 25 | * FlyISVRecognizer is a kind of Singleton calss 26 | * the function can be used as below: 27 | IFLyISVRecognizer *recognizer=[IFlyISVRecognizer creteRecognizer: self]; 28 | */ 29 | 30 | +(instancetype) sharedInstance; 31 | 32 | 33 | /* 34 | * genrerate a serial number password 35 | * princeple: 36 | 1.number serial has no 1 in itself; 37 | 2.the nuber serial has no same number("98765432"is right while "99876543" is wrong) 38 | * @length: the serial number's length,length of "98765432" is 8, 39 | generally length is 8 and other value is forbidden 40 | */ 41 | 42 | -(NSString*) generatePassword:(int)length; 43 | 44 | 45 | 46 | /* 47 | * Used to get password from server 48 | * @pwdt: 49 | when pwdt is 1,the function will return chinese text; 50 | while pwdt is 2, the funciton will return number serial 51 | */ 52 | 53 | -(NSArray*) getPasswordList:(int)pwdt; 54 | 55 | 56 | /* 57 | * Used to judge if the engine is running in listenning 58 | * return value: 59 | YES: the engine is listenning; 60 | No : the engine is not listenning 61 | */ 62 | -(BOOL) isListening; 63 | 64 | 65 | 66 | /* 67 | * Used to query or delete the voiceprint model in server 68 | * @cmd: 69 | "del": delete model 70 | "que": query model 71 | * @authid: user id ,can be @"tianxia" or other; 72 | * @pwdt: voiceprint type 73 | 1: fixed txt voiceprint code ,like @"我的地盘我做主" 74 | 2: free voiceprint code , user can speek anything,but 5 times 75 | trainning the speech shall be same 76 | 3: number serial voiceprint code ,like @"98765432" and so on 77 | * @ptxt: voiceprint txt,only fixed voiceprint and number serial have this, 78 | in free voiceprint model this param shall be set nil 79 | * @vid: another voiceprint type model,user can use this to query or delete 80 | model in server can be @"jakillasdfasdjjjlajlsdfhdfdsadff",totally 32 bits; 81 | * NOTES: 82 | when vid is not nil,then the server will judge the vid first 83 | while the vid is nil, server can still query or delete the voiceprint model 84 | by other params 85 | */ 86 | -(BOOL) sendRequest:(NSString*)cmd authid:(NSString *)auth_id pwdt:(int)pwdt ptxt:(NSString *)ptxt vid:(NSString *)vid err:(int *)err; 87 | 88 | 89 | /* 90 | * set the voiceprint params 91 | * @"sst" : @"train" or @"verify" 92 | * @"auth_id" : @"tianxia" or ther 93 | * @"sub" : @"ivp" 94 | * @"ptxt" : 95 | * @"rgn" : @"5" 96 | * @"pwdt" : @"1",or @"2", or @"3" 97 | * @"auf" : @"audio/L16;rate=16000" or @"audio/L16;rate=8000" 98 | * @"vad_enable : @"1" or @"0" 99 | * @"vad_timeout" : @"3000" 100 | * @"vad_speech_tail": @"100" 101 | */ 102 | -(BOOL) setParameter:(NSString *)value forKey:(NSString *)key; 103 | 104 | 105 | 106 | /* 107 | * get the voiceprint params 108 | * used the same as function of setParameter 109 | */ 110 | -(NSString*) getParameter:(NSString *)key; 111 | 112 | 113 | /* 114 | * start recording 115 | */ 116 | -(void) startListening; 117 | 118 | 119 | /* 120 | * stop recording 121 | */ 122 | -(void) stopListening; 123 | 124 | 125 | /* 126 | * cancel recording,like function stopListening 127 | */ 128 | -(void) cancel; /* cancel recognization */ 129 | 130 | 131 | 132 | 133 | @end 134 | 135 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyMSC.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyMSC.h 3 | // msc 4 | // 5 | // Created by 张剑 on 15/1/14. 6 | // Copyright (c) 2015年 iflytek. All rights reserved. 7 | // 8 | 9 | #ifndef MSC_IFlyMSC_h 10 | #define MSC_IFlyMSC_h 11 | 12 | #import "IFlyContact.h" 13 | #import "IFlyDataUploader.h" 14 | #import "IFlyDebugLog.h" 15 | #import "IFlyISVDelegate.h" 16 | #import "IFlyISVRecognizer.h" 17 | #import "IFlyRecognizerView.h" 18 | #import "IFlyRecognizerViewDelegate.h" 19 | #import "IFlyResourceUtil.h" 20 | #import "IFlySetting.h" 21 | #import "IFlySpeechConstant.h" 22 | #import "IFlySpeechError.h" 23 | #import "IFlySpeechEvaluator.h" 24 | #import "IFlySpeechEvaluatorDelegate.h" 25 | #import "IFlySpeechEvent.h" 26 | #import "IFlySpeechRecognizer.h" 27 | #import "IFlySpeechRecognizerDelegate.h" 28 | #import "IFlySpeechSynthesizer.h" 29 | #import "IFlySpeechSynthesizerDelegate.h" 30 | #import "IFlySpeechUnderstander.h" 31 | #import "IFlySpeechUtility.h" 32 | #import "IFlyTextUnderstander.h" 33 | #import "IFlyUserWords.h" 34 | #import "IFlyPcmRecorder.h" 35 | #import "IFlySpeechEvaluator.h" 36 | #import "IFlySpeechEvaluatorDelegate.h" 37 | 38 | #import "IFlyVoiceWakeuper.h" 39 | #import "IFlyVoiceWakeuperDelegate.h" 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyPcmRecorder.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyPcmRecorder.h 3 | // MSC 4 | 5 | // description: 6 | 7 | // Created by ypzhao on 12-11-15. 8 | // Copyright (c) 2012年 iflytek. All rights reserved. 9 | // 10 | 11 | #import 12 | 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | 19 | 20 | @class IFlyPcmRecorder; 21 | 22 | /** 23 | * 录音协议 24 | */ 25 | @protocol IFlyPcmRecorderDelegate 26 | 27 | /** 28 | * 回调音频数据 29 | * 30 | * @param buffer 音频数据 31 | * @param size 表示音频的长度 32 | */ 33 | - (void) onIFlyRecorderBuffer: (const void *)buffer bufferSize:(int)size; 34 | 35 | /** 36 | * 回调音频的错误码 37 | * 38 | * @param recoder 录音器 39 | * @param error 错误码 40 | */ 41 | - (void) onIFlyRecorderError:(IFlyPcmRecorder*)recoder theError:(int) error; 42 | 43 | @optional 44 | 45 | /** 46 | * 回调录音音量 47 | * 48 | * @param power 音量值 49 | */ 50 | - (void) onIFlyRecorderVolumeChanged:(int) power; 51 | 52 | @end 53 | 54 | 55 | /** 56 | * 录音封装 57 | */ 58 | @interface IFlyPcmRecorder : NSObject 59 | 60 | /** 61 | * 录音委托对象 62 | */ 63 | @property (assign) id delegate; 64 | 65 | /** 66 | * 单例模式 67 | * 68 | * @return 返回录音对象单例 69 | */ 70 | + (instancetype) sharedInstance; 71 | 72 | /** 73 | * 开始录音 74 | * 75 | * @return 开启录音成功返回YES,否则返回NO 76 | */ 77 | - (BOOL) start; 78 | 79 | /** 80 | * 停止录音 81 | */ 82 | - (void) stop; 83 | 84 | /** 85 | * 设置音频采样率 86 | * 87 | * @param rate -[in] 采样率,8k/16k 88 | */ 89 | - (void) setSample:(NSString *) rate; 90 | 91 | /* 92 | * 设置录音时间间隔参数 93 | */ 94 | - (void) setPowerCycle:(float) cycle; 95 | 96 | /** 97 | * 保存录音 98 | * 99 | * @param savePath 音频保存路径 100 | */ 101 | -(void) setSaveAudioPath:(NSString *)savePath; 102 | 103 | @end 104 | 105 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyRecognizerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyRecognizerView.h 3 | // MSC 4 | // 5 | // Created by admin on 13-4-16. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @protocol IFlyRecognizerViewDelegate ; 13 | 14 | /*! 15 | * 语音识别控件 16 | * 录音时触摸控件结束录音,开始识别(相当于旧版的停止);触摸其他位置,取消录音,结束会话(取消) 17 | * 出错时触摸控件,重新开启会话(相当于旧版的再说一次);触摸其他位置,取消录音,结束会话(取消) 18 | * 19 | */ 20 | @interface IFlyRecognizerView : UIView 21 | 22 | /*! 23 | * 设置委托对象 24 | */ 25 | @property(nonatomic,assign)id delegate; 26 | 27 | /*! 28 | * 初始化控件 29 | * 30 | * @param origin 控件左上角的坐标 31 | * 32 | * @return IFlyRecognizerView 对象 33 | */ 34 | - (id)initWithOrigin:(CGPoint)origin; 35 | 36 | /*! 37 | * 初始化控件 38 | * 39 | * @param center 控件中心的坐标 40 | * 41 | * @return IFlyRecognizerView 对象 42 | */ 43 | - (id) initWithCenter:(CGPoint)center; 44 | 45 | /*! 46 | * 设置横竖屏自适应 47 | * 48 | * @param autoRotate 默认值YES,横竖屏自适应 49 | */ 50 | - (void) setAutoRotate:(BOOL)autoRotate; 51 | 52 | /* 53 | * | ------------- |----------------------------------------------------------- 54 | * | 参数 | 描述 55 | * | ------------- |----------------------------------------------------------- 56 | * | domain |应用的领域: 取值为:iat、search、video、poi、music、asr; 57 | * | | iat:普通文本听写; 58 | * | | search:热词搜索; 59 | * | | video:视频音乐搜索; 60 | * | | asr:关键词识别; 61 | * | ------------- |----------------------------------------------------------- 62 | * | vad_bos |前端点检测: 静音超时时间,即用户多长时间不说话则当做超时处理; 单位:ms; 63 | * | | engine指定iat识别默认值为5000; 64 | * | | 其他情况默认值为 4000,范围 0-10000。 65 | * | ------------- |----------------------------------------------------------- 66 | * | vad_eos |后断点检测: 后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 67 | * | | 自动停止录音;单位:ms; 68 | * | | sms 识别默认值为 1800; 69 | * | | 其他默认值为 700,范围 0-10000。 70 | * | ------------- |----------------------------------------------------------- 71 | * | sample_rate |采样率:目前支持的采样率设置有 16000 和 8000。 72 | * | ------------- |----------------------------------------------------------- 73 | * | asr_ptt |标点符号设置: 默认为 1,当设置为 0 时,将返回无标点符号文本。 74 | * | ------------- |----------------------------------------------------------- 75 | * | result_type |返回结果的数据格式: 可设置为json,xml,plain,默认为json。 76 | * | ------------- |----------------------------------------------------------- 77 | * | grammarID |识别的语法id: 只针对 domain 设置为”asr”的应用。 78 | * | ------------- |----------------------------------------------------------- 79 | * | asr_audio_path|音频文件名: 设置此参数后,将会自动保存识别的录音文件。 80 | * | | 路径为Documents/(指定值)。 81 | * | | 不设置或者设置为nil,则不保存音频。 82 | * | ------------- |----------------------------------------------------------- 83 | * | params |扩展参数: 对于一些特殊的参数可在此设置,一般用于设置语义。 84 | * | ------------- |----------------------------------------------------------- 85 | * 86 | */ 87 | 88 | /*! 89 | * 设置识别引擎的参数 90 | * 识别的引擎参数(key)取值如下: 91 | * 92 | * 93 | * 94 | * 95 | * 96 | * 97 | * 98 | * 99 | * 100 | * 101 | * 102 | * 103 | * 104 | * 105 | * 106 | * 107 | *
*参数描述
domain应用的领域: 取值为:iat、search、video、poi、music、asr;
iat:普通文本听写;
search:热词搜索;
video:视频音乐搜索;
video:视频音乐搜索;
asr:关键词识别;
vad_bos前端点检测: 静音超时时间,即用户多长时间不说话则当做超时处理; 单位:ms;
engine指定iat识别默认值为5000;
其他情况默认值为 4000,范围 0-10000。
vad_eos后断点检测: 后端点静音检测时间,即用户停止说话多长时间内即认为不再输入,
自动停止录音;单位:ms;
sms 识别默认值为 1800;
其他默认值为 700,范围 0-10000。
sample_rate采样率:目前支持的采样率设置有 16000 和 8000。
asr_ptt标点符号设置: 默认为 1,当设置为 0 时,将返回无标点符号文本。
result_type返回结果的数据格式: 可设置为json,xml,plain,默认为json。
grammarID识别的语法id: 只针对 domain 设置为”asr”的应用。
asr_audio_path音频文件名: 设置此参数后,将会自动保存识别的录音文件。
路径为Documents/(指定值)。
不设置或者设置为nil,则不保存音频。
params扩展参数: 对于一些特殊的参数可在此设置,一般用于设置语义。
108 | * @param value 参数对应的取值 109 | * @param key 识别引擎参数 110 | * 111 | * @return 成功返回YES;失败返回NO 112 | */ 113 | -(BOOL) setParameter:(NSString *) value forKey:(NSString*)key; 114 | 115 | /*! 116 | * 获取识别引擎参数 117 | * 118 | * @param key 参数key 119 | * 120 | * @return 参数值 121 | */ 122 | -(NSString*) parameterForKey:(NSString *)key; 123 | 124 | /*! 125 | * 开始识别 126 | * 127 | * @return 成功返回YES;失败返回NO 128 | */ 129 | - (BOOL)start; 130 | 131 | /*! 132 | * 取消本次识别 133 | */ 134 | - (void)cancel; 135 | 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyRecognizerViewDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyRecognizerDelegate.h 3 | // MSC 4 | // 5 | // Created by admin on 13-4-16. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class IFlyRecognizerView; 12 | @class IFlySpeechError; 13 | 14 | /*! 15 | * 识别回调委托 16 | */ 17 | @protocol IFlyRecognizerViewDelegate 18 | 19 | /*! 20 | * 回调返回识别结果 21 | * 22 | * @param resultArray 识别结果,NSArray的第一个元素为NSDictionary,NSDictionary的key为识别结果,sc为识别结果的置信度 23 | * @param isLast -[out] 是否最后一个结果 24 | */ 25 | - (void)onResult:(NSArray *)resultArray isLast:(BOOL) isLast; 26 | 27 | /*! 28 | * 识别结束回调 29 | * 30 | * @param error 识别结束错误码 31 | */ 32 | - (void)onError: (IFlySpeechError *) error; 33 | 34 | @optional 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyResourceUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyResourceUtil.h 3 | // MSCDemo 4 | // 5 | // Created by admin on 14-6-20. 6 | // Copyright (c) 2014年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! 12 | * 资源工具类 13 | */ 14 | @interface IFlyResourceUtil : NSObject 15 | 16 | /*! 17 | * 获取通过MSPSetParam,启动引擎的标识 18 | * 19 | * @return 通过MSPSetParam,启动引擎的标识 20 | */ 21 | +(NSString*) ENGINE_START; 22 | 23 | /*! 24 | * 获取通过MSPSetParam,销毁引擎的标识 25 | * 26 | * @return 通过MSPSetParam,销毁引擎的标识 27 | */ 28 | +(NSString*) ENGINE_DESTROY; 29 | 30 | /*! 31 | * 获取识别引擎的资源目录标识 32 | * 33 | * @return 识别引擎的资源目录标识 34 | */ 35 | +(NSString*) ASR_RES_PATH; 36 | 37 | /*! 38 | * 得到语法构建目录 39 | * 40 | * @return 语法构建目录 41 | */ 42 | +(NSString*) GRM_BUILD_PATH; 43 | 44 | /*! 45 | * 获取合成引擎的资源目录标识,同时需要先传入voice_name方可生效 46 | * 47 | * @return 合成引擎的资源目录标识,同时需要先传入voice_name方可生效 48 | */ 49 | +(NSString*) TTS_RES_PATH; 50 | 51 | /*! 52 | * 获取唤醒资源的资源目录标识 53 | * 54 | * @return 唤醒资源的资源目录标识 55 | */ 56 | +(NSString*) IVW_RES_PATH; 57 | 58 | /*! 59 | * 语法类型 60 | * 61 | * @return 语法类型 62 | */ 63 | +(NSString*) GRAMMARTYPE; 64 | 65 | /*! 66 | * 语记SDK专用参数,用于设置本地默认资源路径 67 | * 68 | * @return 本地默认资源路径key字符串 69 | */ 70 | +(NSString*) PLUS_LOCAL_DEFAULT_RES_PATH; 71 | 72 | #pragma mark - 73 | /*! 74 | * 资源存放路径 75 | * 76 | * @param path 设置的路径 77 | * 78 | * @return 资源目录 79 | */ 80 | +(NSString*) generateResourcePath:(NSString *)path; 81 | 82 | /** 83 | * 获得离线发音人对应的id 84 | * 85 | * @param voiceName 发音人名称 86 | * 87 | * @return 有,发音人对应的id;无,返回nil 88 | */ 89 | +(NSString*) identifierForVoiceName:(NSString*)voiceName; 90 | @end 91 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySetting.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySetting.h 3 | // MSC 4 | // 5 | // Created by iflytek on 13-4-12. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! 12 | * 日志打印等级 13 | */ 14 | typedef NS_OPTIONS(NSInteger, LOG_LEVEL){ 15 | /*! 16 | * 全部打印 17 | */ 18 | LVL_ALL = -1, 19 | /*! 20 | * 高,异常分析需要的级别 21 | */ 22 | LVL_DETAIL = 31, 23 | /*! 24 | * 中,打印基本日志信息 25 | */ 26 | LVL_NORMAL = 15, 27 | /*! 28 | * 低,只打印主要日志信息 29 | */ 30 | LVL_LOW = 7, 31 | /*! 32 | * 不打印 33 | */ 34 | LVL_NONE = 0 35 | }; 36 | 37 | /*! 38 | * 此接口为iflyMSC sdk 配置接口。 39 | * 可以获取版本号,设置日志打印等级等 40 | */ 41 | @interface IFlySetting : NSObject 42 | 43 | /*! 44 | * 获取版本号 45 | * 46 | * @return 版本号 47 | */ 48 | + (NSString *) getVersion; 49 | 50 | /*! 51 | * 获取日志等级 52 | * 53 | * @return 返回日志等级 54 | */ 55 | + (LOG_LEVEL) logLvl; 56 | 57 | /*! 58 | * 是否打印控制台log 59 | * 在软件发布时,建议关闭此log。 60 | * 61 | * @param showLog -[in] YES,打印log;NO,不打印 62 | */ 63 | + (void) showLogcat:(BOOL) showLog; 64 | 65 | /*! 66 | * 设置日志msc.log生成路径以及日志等级 67 | * 68 | * 69 | * 70 | * 71 | * 72 | * 73 | * 74 | * 75 | * 76 | * 77 | * 78 | * 79 | *
*日志打印等级描述
LVL_ALL全部打印
LVL_DETAIL高,异常分析需要的级别
LVL_NORMAL中,打印基本日志信息
LVL_LOW低,只打印主要日志信息
LVL_NONE不打印
80 | * 81 | * @param level -[in] 日志打印等级 82 | */ 83 | + (void) setLogFile:(LOG_LEVEL) level; 84 | 85 | /*! 86 | * 设置日志文件的路径 87 | * 日志文件默认存放在Documents目录。 88 | * 89 | * @param path -[in] 日志文件的全路径 90 | */ 91 | + (void) setLogFilePath:(NSString*) path; 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechConstant.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechConstant.h 3 | // MSCDemo 4 | // 5 | // Created by iflytek on 5/9/14. 6 | // Copyright (c) 2014 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! 12 | * 公共常量类 13 | * 主要定义参数的key value值 14 | */ 15 | @interface IFlySpeechConstant : NSObject 16 | 17 | 18 | #pragma mark - 通用参数key 19 | 20 | /*! 21 | * 语音应用ID 22 | * 通过开发者网站申请 23 | * 24 | * @return 语音应用IDkey 25 | */ 26 | +(NSString*)APPID; 27 | 28 | 29 | /*! 30 | * 语言区域。 31 | * 32 | * @return 语言区域key。 33 | */ 34 | +(NSString*)ACCENT; 35 | 36 | /*! 37 | * 语言区域。 38 | * 39 | * @return 普通话value。 40 | */ 41 | +(NSString*)ACCENT_MANDARIN; 42 | 43 | /*! 44 | * 语言区域。 45 | * 46 | * @return 河南话value。 47 | */ 48 | +(NSString*)ACCENT_HENANESE; 49 | 50 | /*! 51 | * 语言区域。 52 | * 53 | * @return 粤语value。 54 | */ 55 | +(NSString*)ACCENT_CANTONESE; 56 | 57 | /*! 58 | * 语言 59 | * 支持:zh_cn,zh_tw,en_us
60 | * 61 | * @return 语言key 62 | */ 63 | +(NSString*)LANGUAGE; 64 | 65 | /*! 66 | * 语言 67 | * 68 | * @return 中文value 69 | */ 70 | +(NSString*)LANGUAGE_CHINESE; 71 | 72 | 73 | /*! 74 | * 语言 75 | * 76 | * @return 中文台湾value 77 | */ 78 | +(NSString*)LANGUAGE_CHINESE_TW; 79 | 80 | /*! 81 | * 语言 82 | * 83 | * @return 英文value 84 | */ 85 | +(NSString*)LANGUAGE_ENGLISH; 86 | 87 | /*! 88 | * 返回结果的数据格式, 89 | * 可设置为json,xml,plain,默认为json。 90 | * 91 | * @return 返回结果的数据格式key 92 | */ 93 | +(NSString*)RESULT_TYPE; 94 | 95 | /*! 96 | * 应用领域。 97 | * 98 | * @return 应用领域key 99 | */ 100 | +(NSString*)IFLY_DOMAIN; 101 | 102 | /*! 103 | * 个性化数据上传类型 104 | * 105 | * @return 个性化数据上传类型key 106 | */ 107 | +(NSString*)DATA_TYPE; 108 | 109 | /*! 110 | * 语音输入超时时间 111 | * 单位:ms,默认30000 112 | * 113 | * @return 语音输入超时时间key 114 | */ 115 | +(NSString*)SPEECH_TIMEOUT; 116 | 117 | /*! 118 | * 网络连接超时时间 119 | * 单位:ms,默认20000 120 | * 121 | * @return 网络连接超时时间key 122 | */ 123 | +(NSString*)NET_TIMEOUT; 124 | 125 | /*! 126 | * 业务类型。 127 | * 128 | * @return 业务类型key。 129 | */ 130 | +(NSString*)SUBJECT; 131 | 132 | /*! 133 | * 扩展参数。 134 | * 135 | * @return 扩展参数key。 136 | */ 137 | +(NSString*)PARAMS; 138 | 139 | /** 140 | * 加密参数 141 | * 142 | * 支持类型:ssl 加密 tcp 非加密 默认:tcp 143 | * 建议对安全性要求较高时使用ssl。 144 | * 145 | * @return 加密参数key 146 | */ 147 | +(NSString*)PROT_TYPE; 148 | 149 | /** 150 | * ssl证书内容 151 | * 152 | * @return ssl证书内容key 153 | */ 154 | +(NSString*)SSL_CERT; 155 | 156 | /*! 157 | * 录音音量返回时间间隔。 158 | * 159 | * @return 间隔key。 160 | */ 161 | +(NSString*)POWER_CYCLE; 162 | 163 | /*! 164 | * 合成、识别、唤醒、评测、声纹等业务采样率。 165 | * 166 | * @return 合成及识别采样率key。 167 | */ 168 | +(NSString*)SAMPLE_RATE; 169 | 170 | /*! 171 | * 合成、识别、唤醒、评测、声纹等业务采样率。 172 | * 173 | * @return 合成及识别采样率8K Value。 174 | */ 175 | +(NSString*)SAMPLE_RATE_8K; 176 | 177 | /*! 178 | * 合成、识别、唤醒、评测、声纹等业务采样率。 179 | * 180 | * @return 合成及识别采样率16K Value。 181 | */ 182 | +(NSString*)SAMPLE_RATE_16K; 183 | 184 | /*! 185 | * 引擎类型。 186 | * 可选:local,cloud,auto 187 | * 默认:auto 188 | * 189 | * @return 引擎类型key。 190 | */ 191 | +(NSString*)ENGINE_TYPE; 192 | 193 | /*! 194 | * 本地识别引擎。 195 | * 196 | * @return 本地识别引擎value。 197 | */ 198 | +(NSString*)TYPE_LOCAL; 199 | 200 | /*! 201 | * 云端识别引擎。 202 | * 203 | * @return 云端识别引擎value。 204 | */ 205 | +(NSString*)TYPE_CLOUD; 206 | 207 | /*! 208 | * 混合识别引擎。 209 | * 210 | * @return 混合识别引擎value。 211 | */ 212 | +(NSString*)TYPE_MIX; 213 | 214 | /*! 215 | * 引擎根据当前配置进行选择。 216 | * 217 | * @return 引擎根据当前配置进行选择value。 218 | */ 219 | +(NSString*)TYPE_AUTO; 220 | 221 | /*! 222 | * 输入文本编码格式。 223 | * 224 | * @return 编码格式key。 225 | */ 226 | +(NSString*)TEXT_ENCODING; 227 | 228 | /*! 229 | * 结果编码格式。 230 | * 231 | * @return 结果编码格式key。 232 | */ 233 | +(NSString*)RESULT_ENCODING; 234 | 235 | /** 236 | * 是否初始化播放器 237 | * SDK内部播放器采用音频队列实现,有部分外部需求需要自定义音频队列,可以通过此开关控制 238 | * 0:不初始化,非0或者参数为空:初始化,默认初始化 239 | * @return 是否初始化播放器 参数key 240 | */ 241 | +(NSString*)PLAYER_INIT; 242 | 243 | /** 244 | * 是否初始化录音器 245 | * SDK内部录音器采用音频队列实现,有部分外部需求需要自定义音频队列,可以通过此开关控制 246 | * 0:不初始化,非0或者参数为空:初始化,默认初始化 247 | * @return 是否初始化录音器 参数key 248 | */ 249 | +(NSString*)RECORDER_INIT; 250 | 251 | #pragma mark - 合成相关设置key 252 | /*! 253 | * 语速 254 | * 范围 (0~100) 默认值:50 255 | * 256 | * @return 语速key 257 | */ 258 | +(NSString*)SPEED; 259 | 260 | /*! 261 | * 音调 262 | * 范围(0~100)默认值:50 263 | * 264 | * @return 音调key 265 | */ 266 | +(NSString*)PITCH; 267 | 268 | /*! 269 | * 合成录音保存路径 270 | * 271 | * @return 合成录音保存路径key 272 | * @注意 只需要设置文件名则可,会自动拼接到IFlySetting setLogFilePath接口设置的目录后 273 | */ 274 | +(NSString*)TTS_AUDIO_PATH; 275 | 276 | /** 277 | * 启用VAD功能 278 | * 279 | * @return 启用VAD功能key 280 | */ 281 | +(NSString*)VAD_ENABLE; 282 | 283 | /*! 284 | * VAD前端点超时 285 | * 范围:0-10000(单位ms) 286 | * 287 | * @return VAD前端点超时key 288 | */ 289 | +(NSString*)VAD_BOS; 290 | 291 | /*! 292 | * VAD后端点超时 。 293 | * 可选范围:0-10000(单位ms) 294 | * 295 | * @return VAD后端点超时key 296 | */ 297 | +(NSString*)VAD_EOS; 298 | 299 | 300 | /* 301 | * 云端支持如下发音人: 302 | * 对于网络TTS的发音人角色,不同引擎类型支持的发音人不同,使用中请注意选择。 303 | * 304 | * |--------|----------------| 305 | * | 发音人 | 参数 | 306 | * |--------|----------------| 307 | * | 小燕 | xiaoyan | 308 | * |--------|----------------| 309 | * | 小宇 | xiaoyu | 310 | * |--------|----------------| 311 | * | 凯瑟琳 | catherine | 312 | * |--------|----------------| 313 | * | 亨利 | henry | 314 | * |--------|----------------| 315 | * | 玛丽 | vimary | 316 | * |--------|----------------| 317 | * | 小研 | vixy | 318 | * |--------|----------------| 319 | * | 小琪 | vixq | 320 | * |--------|----------------| 321 | * | 小峰 | vixf | 322 | * |--------|----------------| 323 | * | 小梅 | vixl | 324 | * |--------|----------------| 325 | * | 小莉 | vixq | 326 | * |--------|----------------| 327 | * | 小蓉 | vixr | 328 | * |--------|----------------| 329 | * | 小芸 | vixyun | 330 | * |--------|----------------| 331 | * | 小坤 | vixk | 332 | * |--------|----------------| 333 | * | 小强 | vixqa | 334 | * |--------|----------------| 335 | * | 小莹 | vixyin | 336 | * |--------|----------------| 337 | * | 小新 | vixx | 338 | * |--------|----------------| 339 | * | 楠楠 | vinn | 340 | * |--------|----------------| 341 | * | 老孙 | vils | 342 | * |--------|----------------| 343 | */ 344 | 345 | /*! 346 | * 发音人 347 | * 348 | * 349 | * 350 | * 351 | * 352 | * 353 | * 354 | * 355 | * 356 | * 357 | * 358 | * 359 | * 360 | * 361 | * 362 | * 363 | * 364 | * 365 | * 366 | * 367 | * 368 | * 369 | * 370 | * 371 | * 372 | *
*云端发音人名称参数
小燕xiaoyan
小宇xiaoyu
凯瑟琳catherine
亨利henry
玛丽vimary
小研vixy
小琪vixq
小峰vixf
小梅vixl
小莉vixq
小蓉(四川话)vixr
小芸vixyun
小坤vixk
小强vixqa
小莹vixying
小新vixx
楠楠vinn
老孙vils
373 | * 374 | * @return 发音人key 375 | */ 376 | +(NSString*)VOICE_NAME; 377 | 378 | /*! 379 | * 发音人ID key。 380 | * @return 发音人ID key 381 | */ 382 | +(NSString*)VOICE_ID; 383 | 384 | /*! 385 | * 发音人语种 key。 386 | * 参数值:0:Auto 1:中文 2英文 ,默认 0. 387 | * @return 发音人ID key 388 | */ 389 | +(NSString*)VOICE_LANG; 390 | 391 | /*! 392 | * 音量 393 | * 范围(0~100) 默认值:50 394 | * 395 | * @return 音量key 396 | */ 397 | +(NSString*)VOLUME ; 398 | 399 | /*! 400 | * 合成音频播放缓冲时间 401 | * 即缓冲多少秒音频后开始播放,如tts_buffer_time=1000; 402 | * 默认缓冲1000ms毫秒后播放。 403 | * 404 | * @return 合成音频播放缓冲时间缓冲时间key 405 | */ 406 | +(NSString*)TTS_BUFFER_TIME ; 407 | 408 | /** 合成数据即时返回 409 | */ 410 | 411 | /** 412 | * 合成数据是否即时返回 413 | * 是否需要数据回调,为1时,当合成一段音频会通过onEvent回调返回,直接合成结束; 414 | * 设置为1为即时返回;0为非即时返回;默认值为0; 415 | * 416 | * @return 成数据即时返回key 417 | */ 418 | +(NSString*)TTS_DATA_NOTIFY; 419 | 420 | /** 421 | * 预合成文本 422 | * 423 | * @return 预合成文本参数key 424 | */ 425 | +(NSString*)NEXT_TEXT; 426 | 427 | /** 428 | * 是否需要打开MPPlayingInfocenter 429 | * 是否需要初始化MPPlayerCenter的属性;0:需要初始化,1:不初始化 430 | * 431 | * @return 是否需要打开MPPlayingInfocenter 参数key 432 | */ 433 | +(NSString*)MPPLAYINGINFOCENTER; 434 | 435 | #pragma mark - 识别、听写、语义相关设置key 436 | 437 | /*! 438 | * 录音源 439 | * 录音时的录音方式,默认为麦克风,设置为1; 440 | * 如果需要外部送入音频,设置为-1,通过WriteAudio接口送入音频。 441 | * 442 | * @return 录音源key 443 | */ 444 | +(NSString*)AUDIO_SOURCE; 445 | 446 | /*! 447 | * 识别录音保存路径 448 | * 449 | * @return 识别录音保存路径key 450 | */ 451 | +(NSString*) ASR_AUDIO_PATH; 452 | 453 | /*! 454 | * 设置是否开启语义 455 | * 456 | * @return 设置是否开启语义key 457 | */ 458 | +(NSString*)ASR_SCH; 459 | 460 | /*! 461 | * 设置是否有标点符号 462 | * 463 | * @return 设置是否有标点符号key 464 | */ 465 | +(NSString*)ASR_PTT; 466 | 467 | /*! 468 | * ASR_PTT 参数值:设置带标点符号 469 | * 470 | * @return 设置是有标点符号Value 471 | */ 472 | +(NSString*)ASR_PTT_HAVEDOT; 473 | 474 | /*! 475 | * ASR_PTT 参数值:设置不带标点符号 476 | * 477 | * @return 设置是无标点符号Value 478 | */ 479 | +(NSString*)ASR_PTT_NODOT; 480 | 481 | /*! 482 | * 本地语法名称。 483 | * 本地语法名称,对应云端的有CLOUD_GRAMMAR 484 | * 485 | * @return 本地语法名称key。 486 | */ 487 | +(NSString*)LOCAL_GRAMMAR; 488 | 489 | /*! 490 | * 云端语法ID。 491 | * 云端编译语法返回的表示,早期版本使用GRAMMAR_ID,仍然兼容,但建议使用新的。 492 | * 493 | * @return 云端语法ID key。 494 | */ 495 | +(NSString*)CLOUD_GRAMMAR; 496 | 497 | /*! 498 | * 语法类型 499 | * 500 | * @return 语法类型key 501 | */ 502 | +(NSString*)GRAMMAR_TYPE; 503 | 504 | /*! 505 | * 语法内容。 506 | * 507 | * @return 语法内容key。 508 | */ 509 | +(NSString*)GRAMMAR_CONTENT; 510 | 511 | /*! 512 | * 字典内容。 513 | * 514 | * @return 字典内容key。 515 | */ 516 | +(NSString*)LEXICON_CONTENT; 517 | 518 | /*! 519 | * 字典名字。 520 | * 521 | * @return 字典名字key。 522 | */ 523 | +(NSString*)LEXICON_NAME; 524 | 525 | /*! 526 | * 语法名称列表。 527 | * 528 | * @return 语法名称列表key。 529 | */ 530 | +(NSString*)GRAMMAR_LIST; 531 | 532 | /*! 533 | * 开放语义协议版本号。 534 | * 如需使用请在http://osp.voicecloud.cn/上进行业务配置 535 | * 536 | * @return 开放语义协议版本号key。 537 | */ 538 | +(NSString*)NLP_VERSION; 539 | 540 | #pragma mark - 唤醒相关设置key 541 | /*! 542 | * 唤醒门限值。 543 | * 544 | * @return 唤醒门限值key。 545 | */ 546 | +(NSString*)IVW_THRESHOLD; 547 | 548 | /*! 549 | * 唤醒服务类型。 550 | * 551 | * @return 唤醒服务类型key。 552 | */ 553 | +(NSString*)IVW_SST; 554 | 555 | /*! 556 | * 唤醒+识别。 557 | * 558 | * @return 唤醒+识别key。 559 | */ 560 | +(NSString*)IVW_ONESHOT; 561 | 562 | /*! 563 | * 唤醒工作方式 564 | * 1:表示唤醒成功后继续录音,0:表示唤醒成功后停止录音。 565 | * 566 | * @return 唤醒工作方式key 567 | */ 568 | +(NSString*)KEEP_ALIVE; 569 | 570 | #pragma mark - 评测相关设置key 571 | /*! 572 | * 评测类型
573 | * 可选值:read_syllable(英文评测不支持):单字;read_word:词语;read_sentence:句子;read_chapter(待开放):篇章。 574 | * 575 | * @return 评测类型 key 576 | */ 577 | +(NSString*)ISE_CATEGORY; 578 | 579 | /*! 580 | * 评测结果等级
581 | * 可选值:complete:完整 ;plain:简单 582 | * 583 | * @return 评测结果等级 key 584 | */ 585 | +(NSString*)ISE_RESULT_LEVEL; 586 | 587 | /*! 588 | * 评测结果格式 589 | * 可选值:xml;plain 590 | * 591 | * @return 评测结果格式 key 592 | */ 593 | +(NSString*)ISE_RESULT_TYPE; 594 | 595 | /*! 596 | * 评测录音保存路径 597 | * 598 | * @return 评测录音保存路径key 599 | */ 600 | +(NSString*) ISE_AUDIO_PATH; 601 | 602 | 603 | /*! 604 | * 朗读跟踪,只对句子和篇章有效
605 | * 可选值:enable:开启;disable:关闭。 606 | * 607 | * @return 朗读跟踪 key 608 | */ 609 | +(NSString*)ISE_AUTO_TRACKING; 610 | 611 | /*! 612 | * 跟踪模式
613 | * 可选值:easy:简单;hard:复杂。 614 | * 615 | * @return 跟踪模式 key 616 | */ 617 | +(NSString*)ISE_TRACK_TYPE; 618 | 619 | #pragma mark - 语记SDK业务key 620 | /** 621 | * 本地所有资源 622 | * 623 | * @return 本地所有资源key 624 | */ 625 | + (NSString *)PLUS_LOCAL_ALL; 626 | 627 | /** 628 | * 本地合成资源 629 | * 630 | * @return 本地合成资源key 631 | */ 632 | + (NSString *)PLUS_LOCAL_TTS; 633 | 634 | /** 635 | * 本地识别资源 636 | * 637 | * @return 本地识别资源key 638 | */ 639 | + (NSString *)PLUS_LOCAL_ASR; 640 | 641 | /** 642 | * 本地唤醒资源 643 | * 644 | * @return 本地唤醒资源key 645 | */ 646 | + (NSString *)PLUS_LOCAL_IVW; 647 | 648 | #pragma mark - 身份验证业务key 649 | 650 | /** 651 | * auth_id 652 | * 用于用户注册和登录、查询、删除等业务时标识用户身份 653 | * 654 | * @return 用户标识 655 | */ 656 | + (NSString*)MFV_AUTH_ID; 657 | 658 | /** 659 | * 请求业务类型,可选值:mfv(默认,融合验证),ivp(声纹),ifr(人脸) 660 | * 661 | * @return 请求业务类型key 662 | */ 663 | + (NSString*)MFV_SUB; 664 | 665 | /** 666 | * 会话类型,不同sub有不同的sst取值。 667 | * ifr:enroll,verify,identify,reenroll,query,delete 668 | * ivp:enroll(train),verify,reenroll,query,delete,download 669 | * 670 | * @return 会话类型key 671 | */ 672 | + (NSString*)MFV_SST; 673 | 674 | /** 675 | * 融合验证模式,仅在融合验证场景下使用。可选值:sin(单一生物特征数据验证),mix(混合生物特征数据验证),agi(灵活生物特征数据验证) 676 | * 677 | * @return 融合验证模式key 678 | */ 679 | + (NSString*)MFV_VCM; 680 | 681 | /** 682 | * 特征场景,用来说明本次验证将涉及的业务。可选值:ivp,ifr,ivp|ifr 683 | * 684 | * @return 特征场景 key 685 | */ 686 | + (NSString*)MFV_SCENES; 687 | 688 | /** 689 | * 确认周期(affirmance cycle,单位:s),用户设置的确认超时时间(生命周期),仅在灵活融合验证场景下使用 690 | * 691 | * @return 确认周期key 692 | */ 693 | + (NSString*)MFV_AFC; 694 | 695 | /** 696 | * 数据保存路径 697 | * 698 | * @return 数据保存路径key 699 | */ 700 | + (NSString*)MFV_DATA_PATH; 701 | 702 | /** 703 | * 训练次数:取值2~9.无默认值,必须明确指定。 704 | * 705 | * @return 训练次数key 706 | */ 707 | + (NSString*)MFV_RGN; 708 | 709 | /** 710 | * 声纹确认门限值,验证得分>=tsd验证通过,否则验证失败(该参数目前不支持,作为保留参数。)却只范围:0~100. 711 | * 712 | * @return 声纹确认门限值key 713 | */ 714 | + (NSString*)MFV_TSD; 715 | 716 | /** 717 | * 密码文本。从服务端下载,比如数字密码所需要的数字串。 718 | * 719 | * @return 密码文本key 720 | */ 721 | + (NSString*)MFV_PTXT; 722 | 723 | /** 724 | * 密码类型。取值:1(文本密码),2(自由说),3(数字密码). 725 | * 726 | * @return 密码类型key 727 | */ 728 | + (NSString*)MFV_PWDT; 729 | 730 | /** 731 | * 取消注册。取值:0(不取消,即不生效),1(取消本次注册). 732 | * 733 | * @return 取消注册key 734 | */ 735 | + (NSString*)MFV_FIN; 736 | 737 | /** 738 | * 等待超时时间:描述客户端等待结果的超时时间 739 | * 740 | * @return 等待超时时间:key 741 | */ 742 | + (NSString*)MFV_WTT; 743 | 744 | /** 745 | * 数据格式 746 | * 声纹为音频采样率支持:16000和8000;人脸为图片格式,支持jpg和gif 747 | * 748 | * @return 数据格式key 749 | */ 750 | + (NSString*)MFV_DATA_FORMAT; 751 | 752 | /** 753 | * 数据压缩编码 754 | * 声纹为;人脸支持raw,不对图片压缩 755 | * 756 | * @return 数据压缩编码key 757 | */ 758 | + (NSString*)MFV_DATA_ENCODING; 759 | 760 | #pragma mark - 人脸业务key 761 | 762 | //1. sub 取值: wfr 用途: 用于区分业务类型,web访问方式中,nginx配置不用使用,但是在结构化日志和染色日志记录中使用。 763 | //2. sst 取值: reg、verify、detect、align 用途: 指定本路会话是属于何种性质 764 | // + 人脸图像注册(reg):上传图像,验证图像的有效性,然后存储起来,作为数据源。 765 | // + 人脸图像验证(verify):通过与指定源图像比较,验证人脸相似性。 766 | // + 人脸图像检测(detect):能够检测出不同姿态方位的人脸在图中的位置。 767 | // + 人脸图像聚焦(align):在给定人脸框下自动标定出两眼、鼻尖、嘴角的坐标。 768 | //3. aue 取值: raw 用途: 图像压缩格式,现在引擎不支持图像压缩,aue只能取值raw 769 | //4. pset 取值: 整数 用途: 人脸识别验证阈值,取值可以是负数也可以是整数。 770 | //5. skip 取值: true/false 用途: 后台图片处理是否进行过滤。true表示不过滤,false表示过滤 771 | //6. gid 取值: *********** 用途: 图像模型id,如:4a6c124ed6b78436ee5aac4563f13eb5 772 | //7. appid 取值:用户申请的appid 用途: 验证用户 773 | 774 | 775 | /** sub 默认值:wfr 776 | * 用于区分业务类型,web访问方式中,nginx配置不用使用,但是在结构化日志和染色日志记录中使用。 777 | */ 778 | + (NSString*) FACE_SUB; 779 | 780 | /** WFR 781 | * sub参数的默认值 782 | */ 783 | + (NSString*) FACE_WFR; 784 | 785 | /** sst 786 | * 指定本路会话是属于何种性质 787 | */ 788 | + (NSString*) FACE_SST; 789 | 790 | /** REG 791 | * 人脸图像注册(reg):上传图像,验证图像的有效性,然后存储起来,作为数据源。 792 | */ 793 | + (NSString*) FACE_REG; 794 | /** VERIFY 795 | * 人脸图像验证(verify):通过与指定源图像比较,验证人脸相似性。 796 | */ 797 | + (NSString*) FACE_VERIFY; 798 | /** DETECT 799 | * 人脸图像检测(detect):能够检测出不同姿态方位的人脸在图中的位置。 800 | */ 801 | + (NSString*) FACE_DETECT; 802 | /** ALIGN 803 | * 人脸图像聚焦(align):在给定人脸框下自动标定出两眼、鼻尖、嘴角的坐标。 804 | */ 805 | + (NSString*) FACE_ALIGN; 806 | 807 | /** ATTR 808 | * 面部属性识别(attr):对面部属性进行识别:例如秃顶、刘海、大嘴、模糊、眼镜等。 809 | */ 810 | + (NSString*) FACE_ATTR; 811 | 812 | 813 | /** AUE 814 | * 图像压缩格式,现在引擎不支持图像压缩,aue只能取值raw 815 | */ 816 | + (NSString*) FACE_AUE; 817 | 818 | /** RAW 819 | * AUE参数的值 820 | */ 821 | + (NSString*) FACE_RAW; 822 | 823 | /** PSET 824 | * 人脸识别验证阈值,取值可以是负数也可以是整数。 825 | */ 826 | + (NSString*) FACE_PSET; 827 | 828 | /** SKIP 829 | * 后台图片处理是否进行过滤。true表示不过滤,false表示过滤,传入字符串@“true”或@“false” 830 | */ 831 | + (NSString*) FACE_SKIP; 832 | 833 | /** GID 834 | * 图像模型id,如:4a6c124ed6b78436ee5aac4563f13eb5 835 | */ 836 | + (NSString*) FACE_GID; 837 | 838 | /** 839 | * auth_id 840 | * 用于用户注册和登录、查询、删除等业务时标识用户身份 841 | * 842 | * @return 用户标识 843 | */ 844 | + (NSString*)FACE_AUTH_ID; 845 | 846 | /** DVC 847 | * 用户设备编号,用于验证用户 848 | */ 849 | + (NSString*) FACE_DVC; 850 | 851 | @end 852 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechError.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechError.h 3 | // MSC 4 | // 5 | // Created by iflytek on 13-3-19. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #ifndef __IFlySpeechError__ 10 | #define __IFlySpeechError__ 11 | 12 | #import 13 | 14 | /*! 15 | * 错误描述类 16 | */ 17 | @interface IFlySpeechError : NSObject 18 | 19 | /*! 20 | * 错误码 21 | */ 22 | @property(nonatomic,assign) int errorCode; 23 | 24 | /*! 25 | * 错误码类 26 | */ 27 | @property(nonatomic,assign) int errorType; 28 | 29 | /*! 30 | * 错误描述 31 | */ 32 | @property(nonatomic,retain) NSString* errorDesc; 33 | 34 | /*! 35 | * 初始化 36 | * 37 | * @param errorCode -[in] 错误码 38 | * 39 | * @return IFlySpeechError对象 40 | */ 41 | + (instancetype) initWithError:(int) errorCode; 42 | 43 | /*! 44 | * 获取错误码 45 | * 46 | * @return 错误码 47 | */ 48 | -(int) errorCode; 49 | 50 | /*! 51 | * 获取错误描述 52 | * 53 | * @return 错误描述 54 | */ 55 | - (NSString *) errorDesc; 56 | 57 | @end 58 | #endif -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechEvaluator.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechEvaluator.h 3 | // msc 4 | // 5 | // Created by jianzhang on 14-1-13 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | #import "IFlySpeechEvaluatorDelegate.h" 12 | 13 | /*! 14 | * 语音评测类 15 | */ 16 | @interface IFlySpeechEvaluator : NSObject 17 | 18 | /*! 19 | * 设置委托对象 20 | */ 21 | @property (assign) id delegate; 22 | 23 | /*! 24 | * 返回评测对象的单例 25 | * 26 | * @return 别对象的单例 27 | */ 28 | + (instancetype)sharedInstance; 29 | 30 | /*! 31 | * 销毁评测对象。 32 | * 33 | * @return 成功返回YES,失败返回NO。 34 | */ 35 | - (BOOL)destroy; 36 | 37 | /*! 38 | * 设置评测引擎的参数 39 | * 40 | * @param value 评测引擎参数值 41 | * @param key 评测引擎参数 42 | * 43 | * @return 设置的参数和取值正确返回YES,失败返回NO 44 | */ 45 | - (BOOL)setParameter:(NSString *)value forKey:(NSString *)key; 46 | 47 | 48 | /*! 49 | * 获得评测引擎的参数 50 | * 51 | * @param key 评测引擎参数 52 | * 53 | * @return key对应的参数值 54 | */ 55 | - (NSString*)parameterForKey:(NSString *)key; 56 | 57 | /*! 58 | * 开始评测 59 | * 同时只能进行一路会话,这次会话没有结束不能进行下一路会话,否则会报错 60 | * 61 | * @param data 评测的试题 62 | * @param params 评测的参数 63 | */ 64 | - (void)startListening:(NSData *)data params:(NSString *)params; 65 | 66 | /*! 67 | * 停止录音 68 | * 调用此函数会停止录音,并开始进行语音识别 69 | */ 70 | - (void)stopListening; 71 | 72 | /*! 73 | * 取消本次会话 74 | */ 75 | - (void)cancel; 76 | 77 | @end 78 | 79 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechEvaluatorDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechEvaluatorDelegate.h 3 | // msc 4 | // 5 | // Created by admin on 13-6-19. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | 12 | @class IFlySpeechError; 13 | 14 | /*! 15 | * 评测协议 16 | */ 17 | @protocol IFlySpeechEvaluatorDelegate 18 | 19 | /*! 20 | * 音量和数据回调 21 | * 22 | * @param volume 音量 23 | * @param buffer 音频数据 24 | */ 25 | - (void)onVolumeChanged:(int)volume buffer:(NSData *)buffer; 26 | 27 | /*! 28 | * 开始录音回调 29 | * 当调用了`startListening`函数之后,如果没有发生错误则会回调此函数。如果发生错误则回调onError:函数 30 | */ 31 | - (void)onBeginOfSpeech; 32 | 33 | /*! 34 | * 停止录音回调 35 | * 当调用了`stopListening`函数或者引擎内部自动检测到断点,如果没有发生错误则回调此函数。 36 | * 如果发生错误则回调onError:函数 37 | */ 38 | - (void)onEndOfSpeech; 39 | 40 | /*! 41 | * 正在取消 42 | */ 43 | - (void)onCancel; 44 | 45 | /*! 46 | * 评测错误回调 47 | * 在进行语音评测过程中的任何时刻都有可能回调此函数,你可以根据errorCode进行相应的处理. 48 | * 当errorCode没有错误时,表示此次会话正常结束,否则,表示此次会话有错误发生。特别的当调用 49 | * `cancel`函数时,引擎不会自动结束,需要等到回调此函数,才表示此次会话结束。在没有回调此函 50 | * 数之前如果重新调用了`startListenging`函数则会报错误。 51 | * 52 | * @param errorCode 错误描述类 53 | */ 54 | - (void)onError:(IFlySpeechError *)errorCode; 55 | 56 | /*! 57 | * 评测结果回调 58 | * 在评测过程中可能会多次回调此函数,你最好不要在此回调函数中进行界面的更改等操作,只需要将回调的结果保存起来。 59 | * 60 | * @param results -[out] 评测结果。 61 | * @param isLast -[out] 是否最后一条结果 62 | */ 63 | - (void)onResults:(NSData *)results isLast:(BOOL)isLast; 64 | 65 | @end 66 | 67 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechEvent.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechEvent.h 3 | // MSCDemo 4 | // 5 | // Created by admin on 14-8-12. 6 | // Copyright (c) 2014年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! 12 | * 事件类型 13 | */ 14 | typedef NS_ENUM(NSUInteger,IFlySpeechEventType){ 15 | /*! 16 | * 网络状态消息 17 | * 在消息到达时,可通过onEvent的第2个参数arg1,获取当前网络连接状态值 18 | */ 19 | IFlySpeechEventTypeNetPref = 10001, 20 | /** 21 | * 转写音频文件消息 22 | * 在录音模式下,成功创建音频文件时返回。可通过onEvent 23 | * 第4个参数data 指定Key为[IFlySpeechConstant IST_AUDIO_PATH],获取音频文件绝对路径. 24 | * 或通过[IFlySpeechTranscripter getParameter:[IFlySpeechConstant IST_AUDIO_PATH]], 25 | * 获取音频文件绝对路径. 26 | */ 27 | IFlySpeechEventTypeISTAudioFile = 10004, 28 | /** 29 | * 转写已上传字节消息 30 | * 在消息到达时,通过onEvent 31 | * 的第二个参数arg1,获取已确认上传到服务器的字节数. 32 | * 若当前音频源为非写音频模式,还可通过onEvent 33 | * 的第三个参数arg2,获取当前所有音频的字节大小.录音模式时,由于所有音频字节大小会变。 34 | * 当停止音频输入后(等待录音时间超时 35 | * [IFlySpeechConstant SPEECH_TIMEOUT] 36 | * ,或调用[IFlySpeechTranscripter stopTranscripting]), 37 | * 且服务器收到所有音频时,第四个参数data,将包含完成标记的布尔值(true),可通过data调用 38 | * 指定KEY为KCIFlySpeechEventKeyISTUploadComplete获取。 39 | * 此消息可能多次返回. 40 | */ 41 | IFlySpeechEventTypeISTUploadBytes = 10006, 42 | 43 | /** 44 | * 转写缓存剩余 45 | * 此消息仅在音频源为-1时需要关注 46 | * 在调用[IFlySpeechTranscripter writeAudio]写音频时,应该关注此事件。 47 | * 此事件在调用写音频接口、及音频最后被写入底库库时分别回调一次。当事件回调时,通过onEvent 48 | * 的第二个参数arg1,获取当前剩余的缓存大小,当缓存小于要写入的音频时,应该先暂停写音频数据,直到下次缓存大小大于要写入的音频时. 49 | * 最大缓存为128KByte。 50 | */ 51 | IFlySpeechEventTypeISTCacheLeft = 10007, 52 | 53 | /** 54 | * 转写结果等待时间消息 55 | * 在消息到达时,通过 onEvent 56 | * 的第二个参数arg1,获取当前结果需要的时间. 57 | * 此消息可能多次返回,返回时间不定,且不一定会返回. 58 | */ 59 | IFlySpeechEventTypeISTResultTime= 10008, 60 | 61 | /** 62 | * 转写转写音频同步ID消息 63 | * 在消息到达时,通过 onEvent 64 | * 的第二个参数arg1,获取当前写音频同步ID. 65 | * 此消息可能多次返回. 66 | */ 67 | IFlySpeechEventTypeISTSyncID= 10009, 68 | 69 | /** 70 | * 会话开始消息 71 | * 在会话开始成功后返回 72 | */ 73 | IFlySpeechEventTypeSessionBegin = 10010, 74 | 75 | /** 76 | * 会话结束消息 77 | * 在会话结束前返回 78 | */ 79 | IFlySpeechEventTypeSessionEnd = 10011, 80 | 81 | /** 82 | * 音量消息,在得到音量时抛出,暂时只有身份验证的声纹业务用到 83 | */ 84 | IFlySpeechEventTypeVolume = 10012, 85 | 86 | /** 87 | * VAD后端点消息,在检测到VAD后端点时抛出,暂时只有身份验证的声纹业务用到 88 | */ 89 | IFlySpeechEventTypeVadEOS = 10013, 90 | 91 | /*! 92 | * 服务端会话id 93 | * 在消息到达时,可通过onEvent的第4个参数data(字典类型), 94 | * 指定key KCIFlySpeechEventKeySessionID,获取服务端会话id. 95 | */ 96 | IFlySpeechEventTypeSessionID = 20001, 97 | 98 | /*! 99 | * TTS合成数据消息 100 | * -(void)onEvent:(int)eventType arg0:(int)arg0 arg1:(int)arg1 data:(NSData *)eventData 101 | * 其中eventData中包含数据 102 | * 103 | */ 104 | IFlySpeechEventTypeTTSBuffer = 21001, 105 | 106 | /*! 107 | * 通知cancel方法被调用的回调 108 | * 109 | */ 110 | IFlySpeechEventTypeTTSCancel = 21002, 111 | 112 | /*! 113 | * IVW onshot 听写 or 识别结果 114 | * 在消息到达时,第2个参数arg1包含是否为最后一个结果:1为是,0为否; 115 | * 第4个参数data中包含数据,通过指定KEY为KCIFlySpeechEventKeyIVWResult获取. 116 | */ 117 | IFlySpeechEventTypeIVWResult = 22001, 118 | 119 | /*! 120 | * 开始处理录音数据 121 | * 122 | */ 123 | IFlySpeechEventTypeSpeechStart= 22002, 124 | 125 | /*! 126 | * 录音停止 127 | * 128 | */ 129 | IFlySpeechEventTypeRecordStop= 22003, 130 | 131 | /*! 132 | * 服务端音频url 133 | * 在消息到达时, 134 | * 第4个参数data,包含数据,通过 135 | * 指定KEY为KCIFlySpeechEventKeyAudioUrl获取. 136 | */ 137 | IFlySpeechEventTypeAudioUrl = 23001, 138 | 139 | /*! 140 | * 变声数据结果返回 141 | * 142 | * 设置voice_change参数获取结果. 143 | */ 144 | IFlySpeechEventTypeVoiceChangeResult = 24001 145 | 146 | }; 147 | 148 | #pragma mark - keys for event data 149 | 150 | /** 151 | * 转写是否已上传完标记key 152 | */ 153 | extern NSString* const KCIFlySpeechEventKeyISTUploadComplete; 154 | 155 | /** 156 | * 服务端会话key 157 | */ 158 | extern NSString* const KCIFlySpeechEventKeySessionID; 159 | /** 160 | * TTS取音频数据key 161 | */ 162 | extern NSString* const KCIFlySpeechEventKeyTTSBuffer; 163 | /** 164 | * IVW oneshot 听写 or 识别结果 key 165 | */ 166 | extern NSString* const KCIFlySpeechEventKeyIVWResult; 167 | /** 168 | * 服务端音频url key 169 | */ 170 | extern NSString* const KCIFlySpeechEventKeyAudioUrl; 171 | 172 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechRecognizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechRecognizer.h 3 | // MSC 4 | // 5 | // Created by iflytek on 13-3-19. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "IFlySpeechRecognizerDelegate.h" 12 | 13 | #define IFLY_AUDIO_SOURCE_MIC @"1" 14 | #define IFLY_AUDIO_SOURCE_STREAM @"-1" 15 | 16 | /*! 17 | * 语音识别类 18 | * 此类现在设计为单例,你在使用中只需要创建此对象,不能调用release/dealloc函数去释放此对象。所有关于语音识别的操作都在此类中。 19 | */ 20 | @interface IFlySpeechRecognizer : NSObject 21 | 22 | /** 设置委托对象 */ 23 | @property(nonatomic,assign) id delegate ; 24 | 25 | /*! 26 | * 返回识别对象的单例 27 | * 28 | * @return 识别对象的单例 29 | */ 30 | + (instancetype) sharedInstance; 31 | 32 | /*! 33 | * 销毁识别对象。 34 | * 35 | * @return 成功返回YES,失败返回NO 36 | */ 37 | - (BOOL) destroy; 38 | 39 | /* 40 | * | ------------- |----------------------------------------------------------- 41 | * | 参数 | 描述 42 | * | ------------- |----------------------------------------------------------- 43 | * | domain |应用的领域: 取值为:iat、search、video、poi、music、asr; 44 | * | | iat:普通文本听写; 45 | * | | search:热词搜索; 46 | * | | video:视频音乐搜索; 47 | * | | asr:关键词识别; 48 | * | ------------- |----------------------------------------------------------- 49 | * | vad_bos |前端点检测: 静音超时时间,即用户多长时间不说话则当做超时处理; 单位:ms; 50 | * | | engine指定iat识别默认值为5000; 51 | * | | 其他情况默认值为 4000,范围 0-10000。 52 | * | ------------- |----------------------------------------------------------- 53 | * | vad_eos |后断点检测: 后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 54 | * | | 自动停止录音;单位:ms; 55 | * | | sms 识别默认值为 1800; 56 | * | | 其他默认值为 700,范围 0-10000。 57 | * | ------------- |----------------------------------------------------------- 58 | * | sample_rate |采样率:目前支持的采样率设置有 16000 和 8000。 59 | * | ------------- |----------------------------------------------------------- 60 | * | asr_ptt |标点符号设置: 默认为 1,当设置为 0 时,将返回无标点符号文本。 61 | * | ------------- |----------------------------------------------------------- 62 | * | result_type |返回结果的数据格式: 可设置为json,xml,plain,默认为json。 63 | * | ------------- |----------------------------------------------------------- 64 | * | grammarID |识别的语法id: 只针对 domain 设置为”asr”的应用。 65 | * | ------------- |----------------------------------------------------------- 66 | * | asr_audio_path|音频文件名: 设置此参数后,将会自动保存识别的录音文件。 67 | * | | 路径为Documents/(指定值)。 68 | * | | 不设置或者设置为nil,则不保存音频。 69 | * | ------------- |----------------------------------------------------------- 70 | * | params |扩展参数: 对于一些特殊的参数可在此设置,一般用于设置语义。 71 | * | ------------- |----------------------------------------------------------- 72 | * 73 | */ 74 | 75 | /*! 76 | * 设置识别引擎的参数 77 | * 识别的引擎参数(key)取值如下: 78 | * 79 | * 80 | * 81 | * 82 | * 83 | * 84 | * 85 | * 86 | * 87 | * 88 | * 89 | * 90 | * 91 | * 92 | * 93 | * 94 | *
*参数描述
domain应用的领域: 取值为:iat、search、video、poi、music、asr;
iat:普通文本听写;
search:热词搜索;
video:视频音乐搜索;
video:视频音乐搜索;
asr:关键词识别;
vad_bos前端点检测: 静音超时时间,即用户多长时间不说话则当做超时处理; 单位:ms;
engine指定iat识别默认值为5000;
其他情况默认值为 4000,范围 0-10000。
vad_eos后断点检测: 后端点静音检测时间,即用户停止说话多长时间内即认为不再输入,
自动停止录音;单位:ms;
sms 识别默认值为 1800;
其他默认值为 700,范围 0-10000。
sample_rate采样率:目前支持的采样率设置有 16000 和 8000。
asr_ptt标点符号设置: 默认为 1,当设置为 0 时,将返回无标点符号文本。
result_type返回结果的数据格式: 可设置为json,xml,plain,默认为json。
grammarID识别的语法id: 只针对 domain 设置为”asr”的应用。
asr_audio_path音频文件名: 设置此参数后,将会自动保存识别的录音文件。
路径为Documents/(指定值)。
不设置或者设置为nil,则不保存音频。
params扩展参数: 对于一些特殊的参数可在此设置,一般用于设置语义。
95 | * @param value 参数对应的取值 96 | * @param key 识别引擎参数 97 | * 98 | * @return 成功返回YES;失败返回NO 99 | */ 100 | -(BOOL) setParameter:(NSString *) value forKey:(NSString*)key; 101 | 102 | /*! 103 | * 获取识别引擎参数 104 | * 105 | * @param key 参数key 106 | * 107 | * @return 参数值 108 | */ 109 | -(NSString*) parameterForKey:(NSString *)key; 110 | 111 | /*! 112 | * 开始识别 113 | * 同时只能进行一路会话,这次会话没有结束不能进行下一路会话,否则会报错。若有需要多次回话, 114 | * 请在onError回调返回后请求下一路回话。 115 | * 116 | * @return 成功返回YES;失败返回NO 117 | */ 118 | - (BOOL) startListening; 119 | 120 | /*! 121 | * 停止录音 122 | * 调用此函数会停止录音,并开始进行语音识别 123 | */ 124 | - (void) stopListening; 125 | 126 | /*! 127 | * 取消本次会话 128 | */ 129 | - (void) cancel; 130 | 131 | /*! 132 | * 上传语法 133 | * 134 | * @param completionHandler 上传语法完成回调 135 | * @param grammarType 语法类型 136 | * @param grammarContent 语法内容 137 | * 138 | * @return 错误码 139 | */ 140 | - (int) buildGrammarCompletionHandler:(IFlyOnBuildFinishCompletionHandler)completionHandler 141 | grammarType:(NSString *)grammarType 142 | grammarContent:(NSString *)grammarContent; 143 | 144 | /** 是否正在识别 145 | */ 146 | @property (nonatomic, readonly) BOOL isListening; 147 | 148 | @end 149 | 150 | /*! 151 | * 音频流识别 152 | * 音频流识别可以将文件分段写入 153 | */ 154 | @interface IFlySpeechRecognizer(IFlyStreamRecognizer) 155 | 156 | /*! 157 | * 写入音频流 158 | * 此方法的使用示例如下: 159 | *
[_iFlySpeechRecognizer setParameter:@"audio_source" value:@"-1"];
160 | * [_iFlySpeechRecognizer startListening];
161 | * [_iFlySpeechRecognizer writeAudio:audioData1];
162 | * [_iFlySpeechRecognizer writeAudio:audioData2];
163 | * ...
164 | * [_iFlySpeechRecognizer stopListening];
165 | * 
166 | * 167 | * @param audioData 音频数据 168 | * 169 | * @return 写入成功返回YES,写入失败返回NO 170 | */ 171 | - (BOOL) writeAudio:(NSData *) audioData; 172 | 173 | @end 174 | 175 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechRecognizerDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechRecognizerDelegate.h 3 | // MSC 4 | // 5 | // Created by ypzhao on 13-3-27. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class IFlySpeechError; 12 | 13 | /*! 14 | * 构建语法结束回调 15 | * 16 | * @param grammarId 语法id 17 | * @param error 错误描述 18 | */ 19 | typedef void(^IFlyOnBuildFinishCompletionHandler)(NSString* grammarId,IFlySpeechError * error); 20 | 21 | 22 | /*! 23 | * 语音识别协议 24 | * 在使用语音识别时,需要实现这个协议中的方法. 25 | */ 26 | @protocol IFlySpeechRecognizerDelegate 27 | 28 | @required 29 | 30 | /*! 31 | * 识别结果回调 32 | * 在进行语音识别过程中的任何时刻都有可能回调此函数,你可以根据errorCode进行相应的处理, 33 | * 当errorCode没有错误时,表示此次会话正常结束;否则,表示此次会话有错误发生。特别的当调用 34 | * `cancel`函数时,引擎不会自动结束,需要等到回调此函数,才表示此次会话结束。在没有回调此函数 35 | * 之前如果重新调用了`startListenging`函数则会报错误。 36 | * 37 | * @param errorCode 错误描述 38 | */ 39 | - (void) onError:(IFlySpeechError *) errorCode; 40 | 41 | /*! 42 | * 识别结果回调 43 | * 在识别过程中可能会多次回调此函数,你最好不要在此回调函数中进行界面的更改等操作,只需要将回调的结果保存起来。 44 | * 使用results的示例如下: 45 | *

 46 |  *  - (void) onResults:(NSArray *) results{
 47 |  *     NSMutableString *result = [[NSMutableString alloc] init];
 48 |  *     NSDictionary *dic = [results objectAtIndex:0];
 49 |  *     for (NSString *key in dic){
 50 |  *        [result appendFormat:@"%@",key];//合并结果
 51 |  *     }
 52 |  *   }
 53 |  *  
54 | * 55 | * @param results -[out] 识别结果,NSArray的第一个元素为NSDictionary,NSDictionary的key为识别结果,sc为识别结果的置信度。 56 | * @param isLast -[out] 是否最后一个结果 57 | */ 58 | - (void) onResults:(NSArray *) results isLast:(BOOL)isLast; 59 | 60 | @optional 61 | 62 | /*! 63 | * 音量变化回调 64 | * 在录音过程中,回调音频的音量。 65 | * 66 | * @param volume -[out] 音量,范围从0-30 67 | */ 68 | - (void) onVolumeChanged: (int)volume; 69 | 70 | /*! 71 | * 开始录音回调 72 | * 当调用了`startListening`函数之后,如果没有发生错误则会回调此函数。 73 | * 如果发生错误则回调onError:函数 74 | */ 75 | - (void) onBeginOfSpeech; 76 | 77 | /*! 78 | * 停止录音回调 79 | * 当调用了`stopListening`函数或者引擎内部自动检测到断点,如果没有发生错误则回调此函数。 80 | * 如果发生错误则回调onError:函数 81 | */ 82 | - (void) onEndOfSpeech; 83 | 84 | /*! 85 | * 取消识别回调 86 | * 当调用了`cancel`函数之后,会回调此函数,在调用了cancel函数和回调onError之前会有一个 87 | * 短暂时间,您可以在此函数中实现对这段时间的界面显示。 88 | */ 89 | - (void) onCancel; 90 | 91 | #ifdef _EDUCATION_ 92 | /** 93 | * 返回音频Key 94 | * 95 | * @param key 音频Key 96 | */ 97 | - (void) getAudioKey:(NSString *)key; 98 | 99 | #endif 100 | 101 | /** 102 | * 扩展事件回调 103 | * 根据事件类型返回额外的数据 104 | * 105 | * @param eventType 事件类型,具体参见IFlySpeechEventType的IFlySpeechEventTypeVoiceChangeResult枚举。 106 | * @param arg0 arg0 107 | * @param arg1 arg1 108 | * @param eventData 事件数据 109 | */ 110 | - (void) onEvent:(int)eventType arg0:(int)arg0 arg1:(int)arg1 data:(NSData *)eventData; 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechSynthesizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechSynthesizer.h 3 | // MSC 4 | // 5 | // Created by 侯效林 on 16-4-22. 6 | // Copyright (c) 2016年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IFlySpeechSynthesizerDelegate.h" 11 | 12 | 13 | /*! 14 | * 语音合成 15 | */ 16 | @interface IFlySpeechSynthesizer : NSObject 17 | 18 | /*! 19 | * 设置识别的委托对象 20 | */ 21 | @property(nonatomic,assign) id delegate; 22 | 23 | /*! 24 | * 返回合成对象的单例 25 | * 26 | * @return 合成对象 27 | */ 28 | + (instancetype) sharedInstance; 29 | 30 | /*! 31 | * 销毁合成对象。 32 | * 33 | * @return 成功返回YES,失败返回NO. 34 | */ 35 | + (BOOL) destroy; 36 | 37 | /* 38 | * | ------------- |----------------------------------------------------------- 39 | * | 参数 | 描述 40 | * | ------------- |----------------------------------------------------------- 41 | * | speed |合成语速,取值范围 0~100 42 | * | ------------- |----------------------------------------------------------- 43 | * | volume |合成的音量,取值范围 0~100 44 | * | ------------- |----------------------------------------------------------- 45 | * | voice_name |默认为”xiaoyan”;可以设置的参数列表可参考个性化发音人列表 46 | * | ------------- |----------------------------------------------------------- 47 | * | sample_rate |采样率:目前支持的采样率设置有 16000 和 8000。 48 | * | ------------- |----------------------------------------------------------- 49 | * | tts_audio_path|音频文件名 设置此参数后,将会自动保存合成的音频文件。 50 | * | |路径为Documents/(指定值)。不设置或者设置为nil,则不保存音频。 51 | * | ------------- |----------------------------------------------------------- 52 | * | params |扩展参数: 对于一些特殊的参数可在此设置。 53 | * | ------------- |----------------------------------------------------------- 54 | * 55 | */ 56 | 57 | /*! 58 | * 设置合成参数 59 | * 60 | * 61 | * 62 | * 63 | * 64 | * 65 | * 66 | * 67 | * 68 | * 69 | * 70 | * 71 | * 72 | *
参数描述
speed合成语速,取值范围 0~100
volume合成的音量,取值范围 0~100
voice_name默认为”xiaoyan”;可以设置的参数列表可参考个性化发音人列表
sample_rate采样率:目前支持的采样率设置有 16000 和 8000。
tts_audio_path音频文件名 设置此参数后,将会自动保存合成的音频文件。
路径为Documents/(指定值)。不设置或者设置为nil,则不保存音频。
params扩展参数: 对于一些特殊的参数可在此设置。
73 | * 74 | * @param value 参数取值 75 | * @param key 合成参数 76 | * 77 | * @return 设置成功返回YES,失败返回NO 78 | */ 79 | -(BOOL) setParameter:(NSString *) value forKey:(NSString*)key; 80 | 81 | /*! 82 | * 获取合成参数 83 | * 84 | * @param key 参数key 85 | * 86 | * @return 参数值 87 | */ 88 | -(NSString*) parameterForKey:(NSString *)key; 89 | 90 | /*! 91 | * 开始合成(播放) 92 | * 调用此函数进行合成,如果发生错误会回调错误`onCompleted` 93 | * 94 | * @param text 合成的文本,最大的字节数为1k 95 | */ 96 | - (void) startSpeaking:(NSString *)text; 97 | 98 | /*! 99 | * 开始合成(不播放) 100 | * 调用此函数进行合成,如果发生错误会回调错误`onCompleted` 101 | * 102 | * @param text 合成的文本,最大的字节数为1k 103 | * @param uri 合成后,保存再本地的音频路径 104 | */ 105 | -(void)synthesize:(NSString *)text toUri:(NSString*)uri; 106 | 107 | /*! 108 | * 暂停播放 109 | * 暂停播放之后,合成不会暂停,仍会继续,如果发生错误则会回调错误`onCompleted` 110 | */ 111 | - (void) pauseSpeaking; 112 | 113 | /*! 114 | * 恢复播放 115 | */ 116 | - (void) resumeSpeaking; 117 | 118 | /*! 119 | * 停止播放并停止合成 120 | */ 121 | - (void) stopSpeaking; 122 | 123 | /*! 124 | * 是否正在播放 125 | */ 126 | @property (nonatomic, readonly) BOOL isSpeaking; 127 | 128 | @end 129 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechSynthesizerDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechSynthesizerDelegate.h 3 | // MSC 4 | // 5 | // Created by ypzhao on 13-3-20. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IFlySpeechEvent.h" 11 | 12 | @class IFlySpeechError; 13 | 14 | /** 15 | * 语音合成回调 16 | */ 17 | @protocol IFlySpeechSynthesizerDelegate 18 | 19 | @required 20 | 21 | /** 22 | * 结束回调 23 | * 当整个合成结束之后会回调此函数 24 | * 25 | * @param error 错误码 26 | */ 27 | - (void) onCompleted:(IFlySpeechError*) error; 28 | 29 | @optional 30 | 31 | /** 32 | * 开始合成回调 33 | */ 34 | - (void) onSpeakBegin; 35 | 36 | /** 37 | * 缓冲进度回调 38 | * 39 | * @param progress 缓冲进度,0-100 40 | * @param msg 附件信息,此版本为nil 41 | */ 42 | - (void) onBufferProgress:(int) progress message:(NSString *)msg; 43 | 44 | /** 45 | * 播放进度回调 46 | * 47 | * @param progress 当前播放进度,0-100 48 | * @param beginPos 当前播放文本的起始位置,0-100 49 | * @param endPos 当前播放文本的结束位置,0-100 50 | */ 51 | - (void) onSpeakProgress:(int) progress beginPos:(int)beginPos endPos:(int)endPos; 52 | 53 | /** 54 | * 暂停播放回调 55 | */ 56 | - (void) onSpeakPaused; 57 | 58 | /** 59 | * 恢复播放回调 60 | */ 61 | - (void) onSpeakResumed; 62 | 63 | /** 64 | * 正在取消回调 65 | * 当调用`cancel`之后会回调此函数 66 | */ 67 | - (void) onSpeakCancel; 68 | 69 | /** 70 | * 扩展事件回调 71 | * 根据事件类型返回额外的数据 72 | * 73 | * @param eventType 事件类型,具体参见IFlySpeechEventType枚举。目前只支持EVENT_TTS_BUFFER也就是实时返回合成音频。 74 | * @param arg0 arg0 75 | * @param arg1 arg1 76 | * @param eventData 事件数据 77 | */ 78 | - (void) onEvent:(int)eventType arg0:(int)arg0 arg1:(int)arg1 data:(NSData *)eventData; 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechUnderstander.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechUnderstander.h 3 | // MSC 4 | // 5 | // Created by iflytek on 2014-03-12. 6 | // Copyright (c) 2014年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class IFlySpeechError; 12 | @protocol IFlySpeechRecognizerDelegate; 13 | 14 | /*! 15 | * 语义理解接口 16 | */ 17 | @interface IFlySpeechUnderstander : NSObject 18 | 19 | /*! 20 | * 是否正在语义理解 21 | */ 22 | @property (readonly) BOOL isUnderstanding; 23 | 24 | /*! 25 | * 设置委托对象 26 | */ 27 | @property(nonatomic,retain) id delegate ; 28 | 29 | /*! 30 | * 创建语义理解对象的单例 31 | * 32 | * @return 语义理解对象 33 | */ 34 | +(instancetype) sharedInstance; 35 | 36 | /*! 37 | * 开始义理解 38 | * 同时只能进行一路会话,这次会话没有结束不能进行下一路会话,否则会报错。若有需要多次回话,请在onError回调返回后请求下一路回话。 39 | * 40 | * @return 成功返回YES,失败返回NO 41 | */ 42 | - (BOOL) startListening; 43 | 44 | /*! 45 | * 停止录音 46 | * 调用此函数会停止录音,并开始进行语义理解 47 | */ 48 | - (void) stopListening; 49 | 50 | /*! 51 | * 取消本次会话 52 | */ 53 | - (void) cancel; 54 | 55 | /* 56 | * | ------------- |----------------------------------------------------------- 57 | * | 参数 | 描述 58 | * | ------------- |----------------------------------------------------------- 59 | * | domain |应用的领域: 取值为:iat、search、video、poi、music、asr; 60 | * | | iat:普通文本听写; 61 | * | | search:热词搜索; 62 | * | | video:视频音乐搜索; 63 | * | | asr:关键词识别; 64 | * | ------------- |----------------------------------------------------------- 65 | * | vad_bos |前端点检测: 静音超时时间,即用户多长时间不说话则当做超时处理; 单位:ms; 66 | * | | engine指定iat识别默认值为5000; 67 | * | | 其他情况默认值为 4000,范围 0-10000。 68 | * | ------------- |----------------------------------------------------------- 69 | * | vad_eos |后断点检测: 后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 70 | * | | 自动停止录音;单位:ms; 71 | * | | sms 识别默认值为 1800; 72 | * | | 其他默认值为 700,范围 0-10000。 73 | * | ------------- |----------------------------------------------------------- 74 | * | sample_rate |采样率:目前支持的采样率设置有 16000 和 8000。 75 | * | ------------- |----------------------------------------------------------- 76 | * | asr_ptt |标点符号设置: 默认为 1,当设置为 0 时,将返回无标点符号文本。 77 | * | ------------- |----------------------------------------------------------- 78 | * | result_type |返回结果的数据格式: 可设置为json,xml,plain,默认为json。 79 | * | ------------- |----------------------------------------------------------- 80 | * | grammarID |识别的语法id: 只针对 domain 设置为”asr”的应用。 81 | * | ------------- |----------------------------------------------------------- 82 | * | asr_audio_path|音频文件名: 设置此参数后,将会自动保存识别的录音文件。 83 | * | | 路径为Documents/(指定值)。 84 | * | | 不设置或者设置为nil,则不保存音频。 85 | * | ------------- |----------------------------------------------------------- 86 | * | params |扩展参数: 对于一些特殊的参数可在此设置,一般用于设置语义。 87 | * | ------------- |----------------------------------------------------------- 88 | * 89 | */ 90 | 91 | /*! 92 | * 设置语义理解引擎的参数 93 | * 语义理解的引擎参数(key)取值如下: 94 | * 95 | * 96 | * 97 | * 98 | * 99 | * 100 | * 101 | * 102 | * 103 | * 104 | * 105 | * 106 | * 107 | * 108 | * 109 | * 110 | *
*参数描述
domain应用的领域: 取值为:iat、search、video、poi、music、asr;
iat:普通文本听写;
search:热词搜索;
video:视频音乐搜索;
video:视频音乐搜索;
asr:关键词识别;
vad_bos前端点检测: 静音超时时间,即用户多长时间不说话则当做超时处理; 单位:ms;
engine指定iat识别默认值为5000;
其他情况默认值为 4000,范围 0-10000。
vad_eos后断点检测: 后端点静音检测时间,即用户停止说话多长时间内即认为不再输入,
自动停止录音;单位:ms;
sms 识别默认值为 1800;
其他默认值为 700,范围 0-10000。
sample_rate采样率:目前支持的采样率设置有 16000 和 8000。
asr_ptt标点符号设置: 默认为 1,当设置为 0 时,将返回无标点符号文本。
result_type返回结果的数据格式: 可设置为json,xml,plain,默认为json。
grammarID识别的语法id: 只针对 domain 设置为”asr”的应用。
asr_audio_path音频文件名: 设置此参数后,将会自动保存识别的录音文件。
路径为Documents/(指定值)。
不设置或者设置为nil,则不保存音频。
params扩展参数: 对于一些特殊的参数可在此设置,一般用于设置语义。
111 | * @param value 参数对应的取值 112 | * @param key 语义理解引擎参数 113 | * 114 | * @return 成功返回YES;失败返回NO 115 | */ 116 | -(BOOL) setParameter:(NSString *) value forKey:(NSString*)key; 117 | 118 | /*! 119 | * 写入音频流 120 | * 121 | * @param audioData 音频数据 122 | * 123 | * @return 写入成功返回YES,写入失败返回NO 124 | */ 125 | - (BOOL) writeAudio:(NSData *) audioData; 126 | 127 | /*! 128 | * 销毁语义理解对象。 129 | * 130 | * @return 成功返回YES;失败返回NO 131 | */ 132 | - (BOOL) destroy; 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlySpeechUtility.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlySpeechUtility.h 3 | // MSCDemo 4 | // 5 | // Created by admin on 14-5-7. 6 | // Copyright (c) 2014年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define iOS_EXCLUSIVE //iOS平台独占API 12 | 13 | @class IFlySpeechError; 14 | 15 | /** 16 | * 引擎模式 17 | */ 18 | typedef NS_ENUM(NSUInteger,IFlyEngineMode){ 19 | /** 20 | * 云端使用MSC,本地优先使用语记 21 | */ 22 | IFlyEngineModeAuto = 0, 23 | /** 24 | * 只使用MSC 25 | */ 26 | IFlyEngineModeMsc, 27 | /** 28 | * 本地只使用语记(受平台限制,云端无法使用语记) 29 | */ 30 | IFlyEngineModePlus, 31 | }; 32 | 33 | 34 | /** 35 | * 服务类型 36 | */ 37 | typedef NS_ENUM(NSUInteger,IFlySpeechPlusServiceType){ 38 | /** 39 | * 打开语记主界面 40 | */ 41 | IFlySpeechPlusServiceTypeNone=0, 42 | /** 43 | * 获取合成资源 44 | */ 45 | IFlySpeechPlusServiceTypeTTS, 46 | /** 47 | * 获取识别资源(未开放) 48 | */ 49 | IFlySpeechPlusServiceTypeISR, 50 | /** 51 | * 获取唤醒资源(未开放) 52 | */ 53 | IFlySpeechPlusServiceTypeIVW, 54 | } ; 55 | 56 | /** 语记返回回调 57 | */ 58 | @protocol IFlySpeechplusDelegate 59 | 60 | /** 61 | * 发生错误 62 | * 63 | * @param errorCode 错误码 64 | */ 65 | - (void)onError:(int)errorCode; 66 | 67 | /** 68 | * 服务正常结束 69 | */ 70 | - (void)onCompleted; 71 | 72 | @end 73 | 74 | /** 75 | * 用户配置 76 | */ 77 | @interface IFlySpeechUtility : NSObject 78 | 79 | /*! 80 | * 创建用户语音配置 81 | * 注册应用请前往语音云开发者网站。
82 | * 网站:http://www.xfyun.cn 83 | * 84 | * @param params 启动参数,必须保证appid参数传入,示例:appid=123456 85 | * 86 | * @return 语音配置对象 87 | */ 88 | + (IFlySpeechUtility*) createUtility:(NSString *) params; 89 | 90 | /*! 91 | * 销毁用户配置对象 92 | * 93 | * @return 成功返回YES,失败返回NO 94 | */ 95 | +(BOOL) destroy; 96 | 97 | /*! 98 | * 获取用户配置对象 99 | * 100 | * @return 用户配置对象 101 | */ 102 | +(IFlySpeechUtility *) getUtility; 103 | 104 | /*! 105 | * 设置MSC引擎的状态参数 106 | * 107 | * @param value 参数值 108 | * @param key 参数名称 109 | * 110 | * @return 成功返回YES,失败返回NO 111 | */ 112 | -(BOOL) setParameter:(NSString *) value forKey:(NSString*)key; 113 | 114 | /** 115 | * 获取MSC引擎状态参数 116 | * 117 | * @param key 参数名 118 | * 119 | * @return 参数值 120 | */ 121 | - (NSString *)parameterForKey:(NSString *)key; 122 | 123 | /** 124 | * 引擎类型 125 | */ 126 | @property (nonatomic, readonly) IFlyEngineMode engineMode; 127 | 128 | /** 129 | * 语记协议委托 130 | */ 131 | @property (nonatomic, assign) id delegate; 132 | 133 | @end 134 | 135 | /** 136 | * 讯飞语记类别 137 | */ 138 | @interface IFlySpeechUtility (SpeechPlus) 139 | 140 | /** 141 | * 检查讯飞语记是否安装 142 | * 143 | * @return 已安装返回YES,否则返回NO 144 | */ 145 | + (BOOL)checkServiceInstalled; 146 | 147 | /** 148 | * 获取讯飞语记下载地址进行下载,安装完成后即可使用服务。 149 | * 下载地址需要通过[[UIApplication sharedApplication] openUrl:]打开 150 | * 151 | * @return 讯飞语记在App Store下载地址 152 | */ 153 | + (NSString *)componentUrl; 154 | 155 | 156 | /** 157 | * 注意:此接口废弃,不再需要使用 158 | * 处理语记使用URL启动第三方应用程序时传递的数据 159 | * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 160 | * 161 | * @param url 语记启动第三方应用程序时传递过来的URL 162 | * 163 | * @return 成功返回YES,失败返回NO。 164 | */ 165 | - (BOOL)handleOpenURL:(NSURL *)url iOS_EXCLUSIVE; 166 | 167 | /** 168 | * 打开讯飞语记获取相应类型服务,0表示打开主界面 169 | * 170 | * @param serviceType 服务类型 171 | * 172 | * @return 成功打开返回YES,否则返回NO 173 | */ 174 | - (BOOL)openSpeechPlus:(IFlySpeechPlusServiceType)serviceType iOS_EXCLUSIVE; 175 | 176 | @end 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyTextUnderstander.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextUnderstand.h 3 | // MSCDemo 4 | // 5 | // Created by iflytek on 4/24/14. 6 | // Copyright (c) 2014 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class IFlySpeechError; 12 | 13 | /*! 14 | * 文本转语义完成回调函数 15 | * 16 | * @param result 成功,返回文本语义理解结果 17 | * @param error 错误描述 18 | */ 19 | typedef void(^IFlyUnderstandTextCompletionHandler)(NSString* result, IFlySpeechError * error); 20 | 21 | /*! 22 | * 文本转语义类 23 | */ 24 | @interface IFlyTextUnderstander : NSObject 25 | 26 | /*! 27 | * 是否正在文本转语义 28 | */ 29 | @property (readonly, atomic) __block BOOL isUnderstanding; 30 | 31 | /*! 32 | * 文本转语义接口 33 | * 输入文本内容,获取语义理解结果 34 | * 35 | * @param text 输入的文本内容 36 | * @param completionHandler 文本转语义完成回调函数 37 | * 38 | * @return 错误码 39 | */ 40 | -(int) understandText:(NSString*)text withCompletionHandler:(IFlyUnderstandTextCompletionHandler) completionHandler; 41 | 42 | /*! 43 | * 设置文本转语义参数 44 | * 45 | * @param value 参数对应的取值 46 | * @param key 文本转语义参数参数 47 | * 48 | * @return 成功返回YES,失败返回NO 49 | */ 50 | -(BOOL) setParameter:(NSString *) value forKey:(NSString*)key; 51 | 52 | /*! 53 | * 取消本次会话 54 | */ 55 | -(void)cancel; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyUserWords.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyUserWords.h 3 | // MSC 4 | // 5 | // Created by ypzhao on 13-2-26. 6 | // Copyright (c) 2013年 iflytek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! 12 | * 用户词表类 13 | * 获取用户词表是为了更好的语音识别(iat),用户词表也属于个性化的一部分. 14 | */ 15 | @interface IFlyUserWords : NSObject 16 | 17 | /*! 18 | * 初始化对象 19 | * 在进行初始化时,需要传入的格式如下: 20 | *
{\"userword\":[{\"name\":\"iflytek\",\"words\":[\"科大讯飞\",
21 |  *  \"云平台\",\"用户词条\",\"开始上传词条\"]}]}
22 | * 23 | * @param json 初始化时传入的数据 24 | * 25 | * @return IFlyUserWords对象 26 | */ 27 | - (id) initWithJson:(NSString *)json; 28 | 29 | /*! 30 | * 将数据转化为上传的数据格式 31 | * 32 | * @return 没有数据或者格式不对时返回nil 33 | */ 34 | - (NSString *) toString; 35 | 36 | /*! 37 | * 返回key对应的数据 38 | * 39 | * @param key 在putword:value中设置的key 40 | * 41 | * @return key对应的数组 42 | */ 43 | - (NSArray *) getWords: (NSString *) key; 44 | 45 | /*! 46 | * 添加一条用户词数据 47 | * 48 | * @param key 用户词对应的key 49 | * @param value 上传的用户词数据 50 | * 51 | * @return 成功返回YES,失败返回NO 52 | */ 53 | - (BOOL) putWord: (NSString *) key value:(NSString *)value; 54 | 55 | /*! 56 | * 添加一组数据 57 | * 58 | * @param key 用户词对应的key 59 | * @param words 上传的用户词数据 60 | * 61 | * @return 成功返回YES,失败返回NO 62 | */ 63 | - (BOOL) putwords: (NSString *) key words:(NSArray *)words; 64 | 65 | /*! 66 | * 是否包含key对应的用户词数据 67 | * 68 | * @param key 用户词对应的key 69 | * 70 | * @return 成功返回YES,失败返回NO 71 | */ 72 | - (BOOL) containsKey: (NSString *) key; 73 | @end 74 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyVoiceWakeuper.h: -------------------------------------------------------------------------------- 1 | // 2 | // IFlyVoiceWakeuper.h 3 | // wakeup 4 | // 5 | // Created by admin on 14-3-18. 6 | // Copyright (c) 2014年 iflytek. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | #import "IFlyVoiceWakeuperDelegate.h" 12 | 13 | /** 14 | 15 | 版本描述:唤醒1.0.0.1 16 | 17 | 语音唤醒资源占用(iPhone5s实测) 18 | 内存占用:3M 19 | CPU占用:< 12% 20 | 21 | 22 | 唤醒服务接口时序描述 23 | 24 | sharedInstance 创建唤醒实例 25 | setParameter 设置服务参数 26 | 27 | 例:[_voiceWakeuper setParameter:@"wake" forKey:@"sst"]; 28 | sst 表示服务类型,wake是唤醒,enroll是注册 29 | 30 | 例:[_voiceWakeuper setParameter:@"m_wakeupResPath" forKey:@"ivw_wake_list"]; 31 | ivw_wake_list 表示唤醒资源的路径 32 | 33 | 例:[_voiceWakeuper setParameter:@"holdValue" forKey:@"ivw_threshold"]; 34 | ivw_threshold 表示唤醒资源的阀值,holdValue形式: 35 | ID:20;15;30 36 | 每个数字代表对应资源的阀值,15表示资源1阀值,20表示资源2阀值,30表示资源3阀值 37 | 本demo只有一个资源设置为ID:20 则可 38 | 39 | startListening启动服务 40 | stopListening 取消服务,但是不释放内部资源 41 | cancel 终止服务,并释放内部资源 42 | 43 | 44 | *参数定义 45 | 46 | * 服务设置参数 47 | sst=wake表示唤醒 48 | sst=enroll表示注册 49 | SESSION_TYPE @"sst" //服务类型 50 | 51 | WAKEUP @"wake" //唤醒 52 | ENROLL @"enroll" //注册 53 | 54 | * 唤醒时,表示资源对应的阀值,为输入值,参数类型为:ID:20;20;3 55 | 已ID为起始,中间用“;”隔开,表示公三个资源,各自阀值对应为20,20和3 56 | IVW_THRESHOLD @"ivw_threshold" //唤醒词对应的门限 57 | 58 | 59 | * 传入参数 60 | 主要是没有定义的参数,依赖params传入 61 | PARAM @"params" 62 | 63 | 64 | * 训练,合并生成的资源路径 65 | 66 | 例:ivw_word_path=/abc/123/newpath.irf 67 | IVW_WORD_PATH @"ivw_word_path" 68 | 69 | 70 | 71 | * 业务成功后的会话持续状态 72 | keep_alive 0:唤醒一次就结束,1:唤醒后继续 73 | KEEP_ALIVE @"keep_alive" 74 | 75 | 76 | * focus_type注册和唤醒的返回参数 77 | wake 唤醒 78 | enroll 注册 79 | FOCUS_TYPE @"focus_type" //服务类型 80 | 81 | 82 | * 服务状态 83 | status=success 服务正常 84 | status=failed 服务失败 85 | status=done 注册完成 86 | STATUS @"status" //服务状态 87 | SUCESS @"success" //服务成功 88 | FAILED @"failed" //服务失败 89 | DONE @"done" //训练完成 90 | 91 | 92 | * 唤醒结果的位置 93 | ID @"id" //唤醒结果的id 94 | 95 | 96 | * 唤醒资源的阀值 97 | 注册时返回,表示注册资源对应的阀值,为输出值 98 | THRESHOLD @"threshold" //训练资源的阀值 99 | 100 | 101 | * 服务结果的可信度 102 | SCORE @"score" //服务结果可信度 103 | 104 | 105 | * 为注册时返回,表示已经注册成功的次数 106 | NUM @"num" //已训练成功次数 107 | 108 | 109 | * 表示服务传入音频对应的起始点和结束点 110 | BOS @"bos" //前端点 111 | EOS @"eos" //后端点 112 | 113 | 114 | * 录音方式,如果是外部数据,设置为-1,通过WriteAudio送入音频 115 | 注意:目前紧紧支持唤醒服务,注册业务尚不支持 116 | AUDIO_SOURCE @"audio_source" 117 | 118 | 119 | * 表示资源合并操作 120 | MERGE_RES_ACTION @"merge" 121 | 122 | */ 123 | 124 | 125 | @interface IFlyVoiceWakeuper : NSObject 126 | { 127 | 128 | } 129 | 130 | @property(assign) id delegate; 131 | 132 | /** 133 | 创建唤醒实例,采用单例模式 134 | */ 135 | + (instancetype) sharedInstance; 136 | 137 | 138 | /** 139 | 启动唤醒 140 | 返回值:YES 成功,NO:失败 141 | */ 142 | -(BOOL) startListening; 143 | 144 | /** 145 | 取消唤醒会话 146 | 注意与cancel的区别,紧紧停止服务,并不释放资源 147 | */ 148 | -(BOOL) stopListening; 149 | 150 | /** 151 | 获取工作参数 152 | */ 153 | -(NSString*) getParameter:(NSString *)key; 154 | 155 | /** 156 | 设置工作参数 157 | 注意服务正在运行中,不能设置参数 158 | */ 159 | -(BOOL) setParameter:(NSString *) value forKey:(NSString*)key; 160 | 161 | /** 162 | 取消唤醒会话,并释放内部资源 163 | */ 164 | -(BOOL) cancel; 165 | 166 | /** 167 | 唤醒业务更新,目前支持合并资源操作 168 | */ 169 | //+(int) updateWords:(NSString *)action params:(NSString*) params; 170 | 171 | /** 172 | 写入录音数据 173 | 暂时紧紧支持唤醒的写入,注册服务尚不支持 174 | */ 175 | //-(int) writeAudio:(const void*)buffer offset:(int)offset length:(int)length; 176 | 177 | @property (readonly) BOOL isListening; 178 | 179 | @end 180 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/Headers/IFlyVoiceWakeuperDelegate.h: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // IFlyVoiceWakeuperDel.h 4 | // wakeup 5 | // 6 | // Created by admin on 14-3-18. 7 | // Copyright (c) 2014年 iflytek. All rights reserved. 8 | // 9 | 10 | 11 | 12 | #import 13 | 14 | @class IFlySpeechError; 15 | 16 | /** 17 | * 代理返回时序描述 18 | 19 | onError 为唤醒会话错误反馈 20 | onBeginOfSpeech 表示录音开始 21 | onVolumeChanged 录音音量大小 22 | onEndOfSpeech 录音结束,当服务终止时返回onEndOfSpeech 23 | onResult 服务结果反馈,内容定义如下 24 | 25 | * 唤醒服务 26 | 27 | 例: 28 | focus_type = wake 唤醒会话 29 | wakeup_result_id = 0 唤醒词位置 30 | wakeup_result_Score = 60 唤醒词可信度 31 | 32 | * 注册服务 33 | 34 | 例: 35 | focus_type = enroll 注册会话 36 | enroll_success_num = 1 当前注册成功次数 37 | current_enroll_status = success/failed 当前会话是否成功 38 | wakeup_result_Score = 60 注册结果可信度 39 | threshold = 10 当注册达到3次后,反馈对应资源的阀值 40 | */ 41 | @protocol IFlyVoiceWakeuperDelegate 42 | 43 | @optional 44 | 45 | /** 46 | 录音开始 47 | */ 48 | -(void) onBeginOfSpeech; 49 | 50 | /** 51 | 录音结束 52 | */ 53 | -(void) onEndOfSpeech; 54 | 55 | /** 56 | 会话错误 57 | @param errorCode 错误描述类, 58 | */ 59 | - (void) onError:(IFlySpeechError *) error; 60 | 61 | /** 62 | 唤醒 63 | resultID:唤醒词位置 64 | */ 65 | -(void) onResult:(NSMutableDictionary *)resultArray; 66 | 67 | /** 68 | 音量反馈,返回频率与录音数据返回回调频率一致 69 | volume:音量值 70 | */ 71 | - (void) onVolumeChanged: (int)volume; 72 | 73 | 74 | /** 扩展事件回调 75 | 76 | 根据事件类型返回额外的数据 77 | 78 | @param eventType 事件类型,具体参见IFlySpeechEvent枚举。 79 | 80 | */ 81 | - (void) onEvent:(int)eventType isLast:(BOOL)isLast arg1:(int)arg1 data:(NSMutableDictionary *)eventData; 82 | 83 | @end 84 | 85 | -------------------------------------------------------------------------------- /src/ios/iflyMSC.framework/iflyMSC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Edc-zhang/cordova-plugin-IFlyspeech/6c48733a4bc917def6bdcceedddd07d523b6f533/src/ios/iflyMSC.framework/iflyMSC -------------------------------------------------------------------------------- /www/Speech.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Edc.zhang on 2017/2/13. 3 | */ 4 | var cordova = require('cordova'), 5 | channel = require('cordova/channel'), 6 | exec = require('cordova/exec'); 7 | 8 | var Speech = function() { 9 | this.channels = { 10 | 'SyncContact': channel.create('SyncContact'), 11 | 'UpdateUserWord': channel.create('UpdateUserWord'), 12 | 'SpeechError': channel.create('SpeechError'), 13 | 'SpeechResults': channel.create('SpeechResults'), 14 | 'VolumeChanged': channel.create('VolumeChanged'), 15 | 'SpeechBegin': channel.create('SpeechBegin'), 16 | 'SpeechEnd': channel.create('SpeechEnd'), 17 | 'SpeechCancel': channel.create('SpeechCancel'), 18 | 'SpeakCompleted': channel.create('SpeakCompleted'), 19 | 'SpeakBegin': channel.create('SpeakBegin'), 20 | 'SpeakProgress': channel.create('SpeakProgress'), 21 | 'SpeakPaused': channel.create('SpeakPaused'), 22 | 'SpeakResumed': channel.create('SpeakResumed'), 23 | 'SpeakCancel': channel.create('SpeakCancel'), 24 | 'BufferProgress': channel.create('BufferProgress') 25 | }; 26 | this.voice_names = { 27 | 'xiaoyan' : '小燕', 28 | 'xiaoyu' : '小宇', 29 | 'vixy' : '小研', 30 | 'vixq' : '小琪', 31 | 'vixf' : '小峰', 32 | 'vixm' : '香港小梅', 33 | 'vixl' : '台湾小莉', 34 | 'vixr' : '四川妹纸', 35 | 'vixyun' : '东北小芸', 36 | 'vixk' : '河南小坤', 37 | 'vixqa' : '湖南小强', 38 | 'vixying' : '陕西小莹', 39 | 'vixx' : '蜡笔小新', 40 | 'vinn' : '楠楠', 41 | 'vils' : '孙大爷', 42 | 'Catherine' : '美国Catherine', 43 | 'henry' : '美国Henry', 44 | 'vimary' : '英国Mary', 45 | 'Mariane' : '法国Mariane', 46 | 'Guli' : '维族Guli', 47 | 'Allabent' : '俄国Allabent', 48 | 'Gabriela' : '西班牙Gabriela', 49 | 'Abha' : '印度Abha', 50 | 'XiaoYun' : '越南XiaoYun' 51 | }; 52 | this.login(); 53 | this.msg = ""; 54 | }; 55 | 56 | Speech.prototype = { 57 | 58 | _eventHandler: function(info) { 59 | if (info.event in this.channels) { 60 | this.channels[info.event].fire(info); 61 | } 62 | }, 63 | 64 | addEventListener: function(event, f, c) { 65 | if (event in this.channels) { 66 | this.channels[event].subscribe(f, c || this); 67 | } 68 | }, 69 | 70 | removeEventListener: function(event, f) { 71 | if (event in this.channels) { 72 | this.channels[event].unsubscribe(f); 73 | } 74 | }, 75 | 76 | login: function() { 77 | // closure variable for local function to use 78 | var speech = this; 79 | 80 | // the callback will be saved in the session for later use 81 | var callback = function(info) { 82 | speech._eventHandler(info); 83 | }; 84 | exec(callback, callback, 'Speech', 'login', []); 85 | 86 | function parseResults( e ) { 87 | var data = JSON.parse( e.results ); 88 | if(data.sn == 1) speech.msg = ""; 89 | var ws = data.ws; 90 | for( var i=0; i