1,判断是否支持语音识别

p_w_picpathbtn = (ImageButton)findViewById(R.id.p_w_picpathBtn01);       p_w_picpathbtn.setOnClickListener(new View.OnClickListener() {                                       @Override           public void onClick(View v) {               // TODO Auto-generated method stub     try{ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);  //设置为当前手机的语言类型  intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "请说话,我识别");//出现语言识别界面上面需要显示的提示   startActivityForResult(intent,REQUEST_CODE);         }catch(ActivityNotFoundException e){   e.printStackTrace();    Toast.makeText(MianActivity.this , "找不到语音设备",     Toast.LENGTH_SHORT).show();                                  }                                       }       });

2,启动语音识别

ArrayList results= data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);           //listView.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,list)); //把数据显示在listview中           String resultsString = "";           resultsString =resultsString+results.get(0);

3,获取识别结果,并以Toast显示出来

Toast.makeText(MianActivity.this, resultsString, Toast.LENGTH_SHORT).show();           super.onActivityResult(requestCode, resultCode,data);


更多相关文章

  1. Android(安卓)显示/隐藏 应用图标
  2. android在Button上显示倒计时
  3. Android(安卓)Spinner不显示下拉箭头解决方案
  4. [置顶] Android加载数据过程中的菊花显示
  5. 【Android】Activity遮罩效果的实现
  6. android spinner 选中后显示字体的颜色设置
  7. Android(安卓)解决 RecyclerView 嵌套 ScrollView 数据显示不全
  8. android camera的基本使用
  9. Android(安卓)将TabHost放在最下方显示

随机推荐

  1. ListView与RadioButton组合——自定义单
  2. Android(安卓)NDK r8b 和 FFmpeg 0.11.2
  3. android 屏蔽电源键,home键
  4. android 设计模式
  5. android.view.WindowLeaked的解决方法
  6. Android音频录制MediaRecorder之简易的录
  7. 消息推送服务厂家对比 个推 - 极光 - 信
  8. android ActionBar介绍
  9. android 使用ContentProvider共享数据
  10. [Android]Fragment的应用/点击替换fragme