Android语音识别简单示例
来源:互联网 发布:星图软件中文版下载 编辑:程序博客网 时间:2024/05/29 15:11
布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="实现语音识别效果" android:id="@+id/tvTitle" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="实现语音识别效果" android:id="@+id/btn" /> <ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/listview" /></LinearLayout>
源代码:
package app.imo;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 SpeakActivity extends Activity implements OnClickListener{private Button btn ;private ListView listView;private static final int REQUEST_CODE = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.speak); btn = (Button) this.findViewById(R.id.btn); listView = (ListView) this.findViewById(R.id.listview); /** * 下面是判断当前手机是否支持语音识别功能 */ PackageManager pm = getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if(list.size()!=0) { btn.setOnClickListener(this); }else{ btn.setEnabled(false); btn.setText("当前语音识别设备不可用..."); } }public void onClick(View v) {if(v.getId()==R.id.btn){/** * 启动手机内置的语言识别功能 */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);}}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {/** * 回调获取从谷歌得到的数据 */if(requestCode==REQUEST_CODE&&resultCode==RESULT_OK){List<String> list = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);listView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list)); //把数据显示在listview中}super.onActivityResult(requestCode, resultCode, data);}}
- Android语音识别简单示例
- Android 语音识别示例
- android语音识别方法示例代码
- android 语音识别接口
- android语音识别简介
- Android语音识别
- android语音识别代码
- android 本地语音识别
- android 语音识别
- android 语音识别
- Android-语音识别
- Android 语音识别
- Android 实现语音识别
- android 语音识别
- android语音识别demo
- android 语音识别
- android语音识别技术
- Android实现语音识别
- axis2 webservice 服务器端和客户端实现例子。
- 给定文件列表,检查目录下的文件是否存在
- 保留 图像的可见部分
- oralce练习题
- 操作系统 第九章 死锁
- Android语音识别简单示例
- 大数据量时Mysql的优化要点
- 关于INNO SETUP 打包程序 在WIN7下 报CREATE PROCESS 错误的权限问题解决方法
- 操作系统 第十章 UNIX系统
- windows自带命令和工具查看端口使用情况
- cobainsoft.windows.forms.barcodecontrol
- Flash8-动态显示汉字乱码问题的解决
- vs2008快捷键使用及诀窍
- 团体补充医疗保险理赔流程