Android 语音输入API使用
- Android 语音输入API使用 转载http://www.javaarch.net/jiagoushi/782.htm
- Android已经支持语音输入的API了,不过不知道中文输入识别效果怎么样。这里给一个怎么使用语音输入的示例
- 首先在android工程中的页面布局文件中res/layout/main.xml添加一个button和text
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_above="@+id/textView1"
- android:layout_toLeftOf="@+id/textView1"
- android:gravity="center"
- android:orientation="vertical" >
- <ImageButton
- android:id="@+id/btnSpeak"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:layout_marginRight="10dp"
- android:layout_marginTop="10dp"
- android:contentDescription="@string/speak"
- android:src="@android:drawable/ic_btn_speak_now" />
- <TextView
- android:id="@+id/txtText"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="10dp"
- android:layout_marginRight="10dp"
- android:layout_marginTop="10dp"
- android:textAppearance="?android:attr/textAppearanceLarge" />
- </LinearLayout>
- active类SpeechToTextDemoActivity.java
- package net.viralpatel.android.speechtotextdemo;
- import java.util.ArrayList;
- import android.app.Activity;
- import android.content.ActivityNotFoundException;
- import android.content.Intent;
- import android.os.Bundle;
- import android.speech.RecognizerIntent;
- import android.view.Menu;
- import android.view.View;
- import android.widget.ImageButton;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- protected static final int RESULT_SPEECH = 1;
- private ImageButton btnSpeak;
- private TextView txtText;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- txtText = (TextView) findViewById(R.id.txtText);
- btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
- btnSpeak.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(
- RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
- intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
- try {
- startActivityForResult(intent, RESULT_SPEECH);
- txtText.setText("");
- } catch (ActivityNotFoundException a) {
- Toast t = Toast.makeText(getApplicationContext(),
- "Opps! Your device doesn't support Speech to Text",
- Toast.LENGTH_SHORT);
- t.show();
- }
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.activity_main, menu);
- return true;
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- switch (requestCode) {
- case RESULT_SPEECH: {
- if (resultCode == RESULT_OK && null != data) {
- ArrayList<String> text = data
- .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
- txtText.setText(text.get(0));
- }
- break;
- }
- }
- }
- }
- 这里android.speech是Android语音输入的核心包,android.speech.RecognizerIntent是一个主要的类,这个active会弹出一个语音输入对话框,然后接收语音输入,识别语音内容转为文本,但我们启动语音输入active后,需要通过startActivityForResult()方法接收文本结果。在.putExtra()方法还需要输入RecognizerIntent.EXTRA_LANGUAGE_MODE语言类型,这里是en-US。
- 我们通过覆盖onActivityResult(int requestCode, int resultCode, Intent data)方法来处理结果数据,通过data获取key为RecognizerIntent.EXTRA_RESULTS来接收文本内容list,然后设置到text框上。
Android 语音输入API使用相关推荐
- android语音输入文字,盘点好用的语音输入APP,懒得打字的时候就说话吧!
原标题:盘点好用的语音输入APP,懒得打字的时候就说话吧! 本文为「智活范」原创作品,欢迎关注我们! 上次推完好用的录音APP后,立刻就有萌友来问了,能不能直接录音转文字呢,这样说话就能生成文字,多省 ...
- 教你用Android做二次开发,识别率达到科大讯飞语音输入水平 | 原力计划
作者 | Pek_KuaiJia 责编 | 夕颜 头图 | CSDN 下载自视觉中国 出品 | CSDN(ID:CSDNnews) 随着目前用户需求的精细化和智能化,很多时候我们需要在App内集成语音 ...
- android上使用蓝牙设备进行语音输入
主要实现步骤如下: 1.确保已经和蓝牙耳机配对连接上. 2.开启蓝牙信道 AudioManager mAudioManager = (AudioManager)getSystemService(Con ...
- 教你用 Android 做二次开发,识别率达到科大讯飞语音输入水平 | 原力计划
作者 | Pek_KuaiJia 责编 | 夕颜 头图 | CSDN 下载自视觉中国 出品 | CSDN(ID:CSDNnews) 随着目前用户需求的精细化和智能化,很多时候我们需要在App内集成语音 ...
- android h5语音输入,H5添加语音输入功能
这次给大家带来H5添加语音输入功能,H5添加语音输入功能的注意事项有哪些,下面就是实战案例,一起来看一下. 这里介绍的是大家以后要用到的html强大功能,可直接给输入框增加语音功能,下面我们先来看看实 ...
- 手机百度输入法环境:android 1.6,百度手机输入法Android 5.1版—新增粤语语音输入...
近日,百度手机输入法发布了全新安卓5.1版,主打离线语音.粤语语音.智能英文.英文单词手写.全新皮肤等功能,获得了不少用户的好评.据了解,百度手机输入法安卓5.1版在原5.0版简约风格的基础上更加专注 ...
- Android 蓝牙耳机 语音输入与播放
Android 蓝牙耳机 语音输入与播放 原以为手机连上蓝牙耳机就能录入语音信号,too young to simple. 经过一番搜寻与折腾,找到两种方式: AudioManager.startBl ...
- Android二次开发之科大讯飞语音输入
随着目前用户需求的精细化和智能化,很多时候我们需要在App内集成语音输入模块,为用户提供语音输入的功能.而科大讯飞语音作为行业内翘楚,识别结果相对准确,且讯飞自带一套识别动画,适合快速搭建模块,废话不 ...
- android手机设置中的语音输入与输出
android手机设置中的语音输入与输出: 设置--语音输入与输出--文字转语音设置--安装语音数据库 在电子市场下载安装,安装成功后,将键盘改为Android键盘,就会看到一个麦克风一样的图标,点击 ...
最新文章
- python——模块1、模块的分类
- JFinal开发环境搭建,JFinal开发案例
- 关于Jsp页面的jstl标签的级联属性的异常。
- kaggle notebook中使用git lfs
- proftpd的配置
- ffmpeg-0.8 开源编码解码库从linux下移植到windows vs2005
- docker mysql配置 丢失_Ubuntu16.04服务器环境配置 – Docker、MySQL、Redis
- 一致性哈希的分析与实现
- 类型转换static_cast,dynamic_cast,const_cast,reinterpret_cast等
- RedHat Linux 7安装CentOS 7 yum源
- linux用cat建文件,如何使用Linux cat命令
- 什么是机器翻译?(科普向)
- 转载】强制删除域控制器
- oracle集群crs,oracle rac集群 crs常用命令(转)
- 使用Java处理键盘输入(DTMF)
- LabVIEW通讯-TCP
- Android studio成品源码项目日历备忘录记事本,该日历备忘录app实现了日历查看
- 向量叉乘矩阵表示_对于向量和矩阵的理解
- 后端获取不到axios.post提交的参数
- Java获取12306余票信息(二)
热门文章
- 计算器软件测试数据,计算器软件测试报告.doc
- mysql金额数字转成中文_数字金额大写转换(可以处理整数,小数,负数)
- AI生成的灌篮高手真人版,爷青回
- 十大监控工具,值得一试
- Flutter AnimatedSwitcher 实现的滑动切换数字动画效果
- 学习笔记(5):第01章-互联网的概述(历史发展+技术发展+常见应用)-互联网的接入(手把手教你调试ADSL宽带技术)
- 关于卷积神经网络,了解一下
- Linux终端和Line discipline图解
- I-P-B frame简介
- ML Notes: Week 2 - Multivariate Linear Regression