Android开发之语音识别
2013-07-03
语音识别
2008年Google语音搜索在iphone平台上线,Android 1.5 将语音识别应用到搜索功能上。
手动输入是目前主要与手机互动的方式,语音搜索宗旨是最大限度地改善人机交互的便捷性。
在玩游戏时,通过语音来控制操作,更显得人性化,体验更佳。
Android 中主要通过RecognizerIntent来实现语音识别。
RecognizerIntent包括的常量
ACTION_RECOGNIZE_SPEECH
ACTION_WEB_SEARCH
EXTRA_LANGUAGE
EXTRA_LANGUAGE_MODEL
EXTRA_MAX_RESULTS
EXTRA_PROMPT
EXTRA_RESULTS
LANGUAGE_MODEL_FREE_FORM
LANGUAGE_MODEL_WEB_SEARCH
RESULT_AUDIO_ERROR
RESULT_CLIENT_ERROR
RESULT_NETWORK_ERROR
RESULT_NO_MATCH
RESULT_SERVER_ERROR
// 打开语音识别
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, VOICE_RECOGNITION_REQUEST_CODE);
在模拟器上找不到语音设备,会抛出异常ActivityNotFoundException。
示例:
点击“开始使用语音识别”按钮后,开始语音输入,然后在onActivityResult方法中取得结果并显示出来
protect void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
StringBuffer sb = new StringBuffer();
for(int i=0; i<results.size; i++) {
sb.append(results.get(i));
}
Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();
super.onActivityResult(requestCode, resultCode, data);
}
}
相关文章
- 聚焦 Android 11: 大功告成
- 74款android开机动画,修改Android系统开机动画
- android 混淆规则作用,Android代码混淆详解
- android deeplink流程,Android Deeplink探究[通俗易懂]
- android sdk安装过程,图文详解Android 3.0 SDK安装教程
- android 定时器实例,Android定时器和Handler用法实例分析
- android telephony 原理解析与开发指南_Android逆向pdf
- android toast显示时间,Android Toast自定义显示时间「建议收藏」
- 3.Android-传感器开发-处理各种传感器配置[通俗易懂]
- Android studio更新后出现警告:Warning:The `android.dexOptions.incremental` property is deprecated and it has
- 【错误记录】Android Studio 编译报错 ( Could not find com.android.tools.build:gradle:4.2.1. )
- 【错误记录】编译 Android 版本的 ijkplayer 报错 ( ./init-android.sh: 第 37 行: cd: android/contrib/: 没有那个文件或目录 )
- 【ijkplayer】编译 Android 版本的 ijkplayer ⑥ ( 进入 ijkplayer-android/android 目录 | 执行 compile-ijk.sh 脚本完成编译 )
- 【Kotlin 协程】协程简介 ( 协程概念 | 协程作用 | 创建 Android 工程并进行协程相关配置开发 | 异步任务与协程对比 )
- [android] notification入门详解手机开发
- Android中android:visibility的3中属性的剖析详解手机开发
- Android使用Pull解析器解析xml文件的实现代码
- 理解Android的手势识别提高APP的用户体验
- Android中的android:layout_weight使用详解
- ANDROID应用程序的混淆打包分享
- android自定义控件和自定义回调函数步骤示例
- Android提高之TelephonyManager功能探秘