赞
踩
根据对应平台导入
注意事项: 1.eclipse 直接导入libs 就行了,as:分别导入 libs和jniLibs.
2.android 5.0 要导入 armeabi和 armeabi-v7a 才能正常使用 不导入情况如下:
还有一个就是组件没安装错误....
appid:创建一个application:
3.创建 语音听写对象:
com.iflytek.cloud.SpeechRecognizer mIat= com.iflytek.cloud.SpeechRecognizer.createRecognizer(this, null); mIat.setParameter(SpeechConstant.DOMAIN, "iat"); mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn"); mIat.setParameter(SpeechConstant.ACCENT, "mandarin ");
4.创建对话框
RecognizerDialog mDialog = new RecognizerDialog(this, mInitListener); mDialog.setParameter(SpeechConstant.LANGUAGE, "zh_cn"); mDialog.setParameter(SpeechConstant.ACCENT, "mandarin"); mDialog.setListener(mRecognizerDialogListener);
接口直接alt+enter 生成看命名就知道其作用
5.监听语音对象和显示对话框
注意事项:startlistening() 监听不能放在.show()下面:不然会有bug
而且执行onresult的是mdialog里面的监听方法,并不会执行 mRecoListener里面的onresult方法,虽然换一下位置是可以执行...但有bug
6.在onresult 中解析生成的结果
private void printResult(RecognizerResult results) { String text = JsonParser.parseIatResult(results.getResultString()); String sn = ""; // 读取json结果中的sn字段 try { JSONObject resultJson = new JSONObject(results.getResultString()); sn = resultJson.optString("sn"); } catch (JSONException e) { e.printStackTrace(); } mIatResults.put(sn, text); // StringBuffer resultBuffer = new StringBuffer(); for (String key : mIatResults.keySet()) { resultBuffer.append(mIatResults.get(key)); } String s = new String(resultBuffer); // s.endsWith(""); // et_speech.setText(new String(resultBuffer).replaceAll("\\W","")); et_speech.setText(resultBuffer);
注意事项:onresult 会执行多次,所以需要一个集合存储句子.....
更多信息:http://www.xfyun.cn/doccenter/awd
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。