一、当天完成的任务
划水了一天,导入了module,弄了个百度语音的程序,效果不太行,识别率不怎么高。
贴个代码:
public class MainActivity extends AppCompatActivity { private static final String TAG = MainActivity.class.getSimpleName(); private Button mOpenSpeechDialogBtn; private Button mOpenSpeechLongDialogBtn; private TextView mResultTv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); onePermission(); initViews(); initEvents(); } private void initViews() { mOpenSpeechDialogBtn = findViewById(R.id.btn_openSpeechDialog); mOpenSpeechLongDialogBtn = findViewById(R.id.btn_openSpeechLongDialog); mResultTv = findViewById(R.id.tv_result); } private void initEvents() { mOpenSpeechDialogBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //打开百度语音对话框 SpeechBottomSheetDialog speechBottomSheetDialog = SpeechBottomSheetDialog.getInstance(MainActivity.this); speechBottomSheetDialog.seOnResultListItemClickListener(new SpeechBottomSheetDialog.OnResultListItemClickListener() { @Override public void onItemClick(String title) { //填充到输入框中 mResultTv.setText(title); } }); speechBottomSheetDialog.show(getSupportFragmentManager(), TAG); } }); mOpenSpeechLongDialogBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //打开百度语音对话框 SpeechLongBottomSheetDialog speechLongBottomSheetDialog = SpeechLongBottomSheetDialog.getInstance(MainActivity.this); speechLongBottomSheetDialog.seOnResultListItemClickListener(new SpeechLongBottomSheetDialog.OnResultListItemClickListener() { @Override public void onItemClick(String title) { //填充到输入框中 mResultTv.setText(mResultTv.getText()+title); } }); speechLongBottomSheetDialog.show(getSupportFragmentManager(), TAG); } }); } /**只有一个运行时权限申请的情况*/ private void onePermission(){ RxPermissions rxPermissions = new RxPermissions(MainActivity.this); // where this is an Activity instance rxPermissions.request(Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE) //权限名称,多个权限之间逗号分隔开 .subscribe(new Consumer<Boolean>() { @Override public void accept(Boolean granted) throws Exception { Log.e(TAG, "{accept}granted=" + granted);//执行顺序——1【多个权限的情况,只有所有的权限均允许的情况下granted==true】 if (granted) { // 在android 6.0之前会默认返回true // 已经获取权限 } else { // 未获取权限 Toast.makeText(MainActivity.this, "您没有授权该权限,请在设置中打开授权", Toast.LENGTH_SHORT).show(); } } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { Log.e(TAG,"{accept}");//可能是授权异常的情况下的处理 } }, new Action() { @Override public void run() throws Exception { Log.e(TAG,"{run}");//执行顺序——2 } }); } }
效果图明天整理好再贴
二、第二天的计划
把语音识别都弄好吧。
三、每日小结
①之前都是导jar包,今天还是第一次导module,挺麻烦的。
②识别不出来也没办法啊,免费版就这样了,。,
③中国队给爷冲
原文地址:https://www.cnblogs.com/RecKono/p/11440246.html
时间: 2024-11-08 17:33:32