android VoiceRecognition 语音识别并打印到列表上
来源:互联网 发布:模拟装修设计软件 编辑:程序博客网 时间:2024/06/05 17:14
package com.example.wenandroid;import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.content.Intent;import android.content.pm.PackageManager;import android.content.pm.ResolveInfo;import android.os.Bundle;import android.speech.RecognizerIntent;import android.view.View;import android.view.View.OnClickListener;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.ListView;public class VoiceRecognizeDemo extends Activity implements OnClickListener {private static final int VOICE_RECOGNITION_REQUEST_CODE=1234;private ListView listview;private Button btn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.voicerecogenize);listview=(ListView)findViewById(R.id.listview);btn=(Button)findViewById(R.id.btn);PackageManager pm=getPackageManager();List<ResolveInfo> activities = pm.queryIntentActivities( new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { btn.setOnClickListener(this); } else { btn.setEnabled(false); btn.setText("Recognizer not present"); }}@Overridepublic void onClick(View v) {if(v.getId()==R.id.btn){startVoiceRecognitionActivity();}}private void startVoiceRecognitionActivity(){Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) { // Fill the list view with the strings the recognizer thought it could have heard ArrayList<String> matches = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches)); }super.onActivityResult(requestCode, resultCode, data);}}
界面只有一个listview和一个button。
- android VoiceRecognition 语音识别并打印到列表上
- android中VoiceRecognition的使用
- Android开发学习之使用百度语音识别SDK实现语音识别(上)
- Android利用RecognizerIntent识别语音并简单实现打电话动作
- 如何在android平台上实现语音识别
- 关于android上调用google的语音识别功能
- 如何在android平台上实现语音识别
- android 语音识别接口
- android语音识别简介
- Android语音识别
- android语音识别代码
- android 本地语音识别
- android 语音识别
- android 语音识别
- Android-语音识别
- Android 语音识别
- Android 实现语音识别
- android 语音识别
- xp下删除ubuntu系统
- strcmp函数和strcpy函数
- 收集的一些题or结论
- spring实例化bean之简单工厂静态方法实例化
- DOS命令下执行Java代码 整理
- android VoiceRecognition 语音识别并打印到列表上
- 初创公司的财务问题
- Hibernate中关联关系的配置
- 几何方法---扩展的平面
- Valgrind 进行linux程序调试的详细说明
- eclipse 编码
- AFNetworking使用
- 用va_list实现变参函数
- QT介绍