赞
踩
private static final String TAG = “MainActivity”;
private SpeechRecognizer mIat;// 语音听写对象
private RecognizerDialog mIatDialog;// 语音听写UI
// 用HashMap存储听写结果
private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
private SharedPreferences mSharedPreferences;//缓存
private String mEngineType = SpeechConstant.TYPE_CLOUD;// 引擎类型
private String language = “zh_cn”;//识别语言
private TextView tvResult;//识别结果
private Button btnStart;//开始识别
private String resultType = “json”;//结果内容数据格式
同时你要实现这个点击事件的监听
实现一个方法
@Override
public void onClick(View v) {
//写入点击之后处理逻辑
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvResult = findViewById(R.id.tv_result);
btnStart = findViewById(R.id.btn_start);
btnStart.setOnClickListener(this);//实现点击监听
}
/**
*/
private void initPermission() {
String permissions[] = {Manifest.permission.RECORD_AUDIO,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.INTERNET,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
ArrayList toApplyList = new ArrayList();
for (String perm : permissions) {
if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, perm)) {
toApplyList.add(perm);
}
}
String tmpList[] = new String[toApplyList.size()];
if (!toApplyList.isEmpty()) {
ActivityCompat.requestPermissions(this, toApplyList.toArray(tmpList), 123);
}
}
/**
权限申请回调,可以作进一步处理
@param requestCode
@param permissions
@param grantResults
*/
@Override
public void onRequ
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。