public class SoundTestActivity extends Activity {
/** Called when the activity is first created. */
private static final int RECOGNIZER_EXAMPLE=101;
private TextView result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
result=(TextView)findViewById(R.id.text_result);
Button start=(Button)findViewById(R.id.start_button);
start.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word or phrase\nand it will show as text");
startActivityForResult(intent,RECOGNIZER_EXAMPLE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode==RECOGNIZER_EXAMPLE&&resultCode==RESULT_OK){
ArrayList<String> resultList=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
StringBuffer resultListString=new StringBuffer();;
for(String s:resultList){
resultListString.append(s+",");
}
result.setText(resultListString.toString());
}
super.onActivityResult(requestCode, resultCode, data);

}

}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android 屏幕截屏
  2. android常用的代码片段
  3. android 上面的分享功能
  4. Android获取手机中的所有音乐地址
  5. Timer使用
  6. Android(安卓)定义全局LOG打印日志,并显示
  7. android 添加和删除快捷方式
  8. Android主流IOC框架浅析(Java注解反射原理
  9. android 检测应用程序信息
  10. Android(安卓)监听返回键|您确定要退出吗