1. Android 语音输入API使用 转载http://www.javaarch.net/jiagoushi/782.htm
  2. Android已经支持语音输入的API了,不过不知道中文输入识别效果怎么样。这里给一个怎么使用语音输入的示例
  3. 首先在android工程中的页面布局文件中res/layout/main.xml添加一个button和text
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5. xmlns:tools="http://schemas.android.com/tools"
  6. android:layout_width="fill_parent"
  7. android:layout_height="wrap_content"
  8. android:layout_above="@+id/textView1"
  9. android:layout_toLeftOf="@+id/textView1"
  10. android:gravity="center"
  11. android:orientation="vertical" >
  12. <ImageButton
  13. android:id="@+id/btnSpeak"
  14. android:layout_width="fill_parent"
  15. android:layout_height="wrap_content"
  16. android:layout_margin="10dp"
  17. android:layout_marginRight="10dp"
  18. android:layout_marginTop="10dp"
  19. android:contentDescription="@string/speak"
  20. android:src="@android:drawable/ic_btn_speak_now" />
  21. <TextView
  22. android:id="@+id/txtText"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:layout_marginLeft="10dp"
  26. android:layout_marginRight="10dp"
  27. android:layout_marginTop="10dp"
  28. android:textAppearance="?android:attr/textAppearanceLarge" />
  29. </LinearLayout>
  30. active类SpeechToTextDemoActivity.java
  31. package net.viralpatel.android.speechtotextdemo;
  32. import java.util.ArrayList;
  33. import android.app.Activity;
  34. import android.content.ActivityNotFoundException;
  35. import android.content.Intent;
  36. import android.os.Bundle;
  37. import android.speech.RecognizerIntent;
  38. import android.view.Menu;
  39. import android.view.View;
  40. import android.widget.ImageButton;
  41. import android.widget.TextView;
  42. import android.widget.Toast;
  43. public class MainActivity extends Activity {
  44. protected static final int RESULT_SPEECH = 1;
  45. private ImageButton btnSpeak;
  46. private TextView txtText;
  47. @Override
  48. public void onCreate(Bundle savedInstanceState) {
  49. super.onCreate(savedInstanceState);
  50. setContentView(R.layout.activity_main);
  51. txtText = (TextView) findViewById(R.id.txtText);
  52. btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
  53. btnSpeak.setOnClickListener(new View.OnClickListener() {
  54. @Override
  55. public void onClick(View v) {
  56. Intent intent = new Intent(
  57. RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  58. intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
  59. try {
  60. startActivityForResult(intent, RESULT_SPEECH);
  61. txtText.setText("");
  62. } catch (ActivityNotFoundException a) {
  63. Toast t = Toast.makeText(getApplicationContext(),
  64. "Opps! Your device doesn't support Speech to Text",
  65. Toast.LENGTH_SHORT);
  66. t.show();
  67. }
  68. }
  69. });
  70. }
  71. @Override
  72. public boolean onCreateOptionsMenu(Menu menu) {
  73. getMenuInflater().inflate(R.menu.activity_main, menu);
  74. return true;
  75. }
  76. @Override
  77. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  78. super.onActivityResult(requestCode, resultCode, data);
  79. switch (requestCode) {
  80. case RESULT_SPEECH: {
  81. if (resultCode == RESULT_OK && null != data) {
  82. ArrayList<String> text = data
  83. .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
  84. txtText.setText(text.get(0));
  85. }
  86. break;
  87. }
  88. }
  89. }
  90. }
  91. 这里android.speech是Android语音输入的核心包,android.speech.RecognizerIntent是一个主要的类,这个active会弹出一个语音输入对话框,然后接收语音输入,识别语音内容转为文本,但我们启动语音输入active后,需要通过startActivityForResult()方法接收文本结果。在.putExtra()方法还需要输入RecognizerIntent.EXTRA_LANGUAGE_MODE语言类型,这里是en-US。
  92. 我们通过覆盖onActivityResult(int requestCode, int resultCode, Intent data)方法来处理结果数据,通过data获取key为RecognizerIntent.EXTRA_RESULTS来接收文本内容list,然后设置到text框上。

Android 语音输入API使用相关推荐

  1. android语音输入文字,盘点好用的语音输入APP,懒得打字的时候就说话吧!

    原标题:盘点好用的语音输入APP,懒得打字的时候就说话吧! 本文为「智活范」原创作品,欢迎关注我们! 上次推完好用的录音APP后,立刻就有萌友来问了,能不能直接录音转文字呢,这样说话就能生成文字,多省 ...

  2. 教你用Android做二次开发,识别率达到科大讯飞语音输入水平 | 原力计划

    作者 | Pek_KuaiJia 责编 | 夕颜 头图 | CSDN 下载自视觉中国 出品 | CSDN(ID:CSDNnews) 随着目前用户需求的精细化和智能化,很多时候我们需要在App内集成语音 ...

  3. android上使用蓝牙设备进行语音输入

    主要实现步骤如下: 1.确保已经和蓝牙耳机配对连接上. 2.开启蓝牙信道 AudioManager mAudioManager = (AudioManager)getSystemService(Con ...

  4. 教你用 Android 做二次开发,识别率达到科大讯飞语音输入水平 | 原力计划

    作者 | Pek_KuaiJia 责编 | 夕颜 头图 | CSDN 下载自视觉中国 出品 | CSDN(ID:CSDNnews) 随着目前用户需求的精细化和智能化,很多时候我们需要在App内集成语音 ...

  5. android h5语音输入,H5添加语音输入功能

    这次给大家带来H5添加语音输入功能,H5添加语音输入功能的注意事项有哪些,下面就是实战案例,一起来看一下. 这里介绍的是大家以后要用到的html强大功能,可直接给输入框增加语音功能,下面我们先来看看实 ...

  6. 手机百度输入法环境:android 1.6,百度手机输入法Android 5.1版—新增粤语语音输入...

    近日,百度手机输入法发布了全新安卓5.1版,主打离线语音.粤语语音.智能英文.英文单词手写.全新皮肤等功能,获得了不少用户的好评.据了解,百度手机输入法安卓5.1版在原5.0版简约风格的基础上更加专注 ...

  7. Android 蓝牙耳机 语音输入与播放

    Android 蓝牙耳机 语音输入与播放 原以为手机连上蓝牙耳机就能录入语音信号,too young to simple. 经过一番搜寻与折腾,找到两种方式: AudioManager.startBl ...

  8. Android二次开发之科大讯飞语音输入

    随着目前用户需求的精细化和智能化,很多时候我们需要在App内集成语音输入模块,为用户提供语音输入的功能.而科大讯飞语音作为行业内翘楚,识别结果相对准确,且讯飞自带一套识别动画,适合快速搭建模块,废话不 ...

  9. android手机设置中的语音输入与输出

    android手机设置中的语音输入与输出: 设置--语音输入与输出--文字转语音设置--安装语音数据库 在电子市场下载安装,安装成功后,将键盘改为Android键盘,就会看到一个麦克风一样的图标,点击 ...

最新文章

  1. python——模块1、模块的分类
  2. JFinal开发环境搭建,JFinal开发案例
  3. 关于Jsp页面的jstl标签的级联属性的异常。
  4. kaggle notebook中使用git lfs
  5. proftpd的配置
  6. ffmpeg-0.8 开源编码解码库从linux下移植到windows vs2005
  7. docker mysql配置 丢失_Ubuntu16.04服务器环境配置 – Docker、MySQL、Redis
  8. 一致性哈希的分析与实现
  9. 类型转换static_cast,dynamic_cast,const_cast,reinterpret_cast等
  10. RedHat Linux 7安装CentOS 7 yum源
  11. linux用cat建文件,如何使用Linux cat命令
  12. 什么是机器翻译?(科普向)
  13. 转载】强制删除域控制器
  14. oracle集群crs,oracle rac集群 crs常用命令(转)
  15. 使用Java处理键盘输入(DTMF)
  16. LabVIEW通讯-TCP
  17. Android studio成品源码项目日历备忘录记事本,该日历备忘录app实现了日历查看
  18. 向量叉乘矩阵表示_对于向量和矩阵的理解
  19. 后端获取不到axios.post提交的参数
  20. Java获取12306余票信息(二)

热门文章

  1. 计算器软件测试数据,计算器软件测试报告.doc
  2. mysql金额数字转成中文_数字金额大写转换(可以处理整数,小数,负数)
  3. AI生成的灌篮高手真人版,爷青回
  4. 十大监控工具,值得一试
  5. Flutter AnimatedSwitcher 实现的滑动切换数字动画效果
  6. 学习笔记(5):第01章-互联网的概述(历史发展+技术发展+常见应用)-互联网的接入(手把手教你调试ADSL宽带技术)
  7. 关于卷积神经网络,了解一下
  8. Linux终端和Line discipline图解
  9. I-P-B frame简介
  10. ML Notes: Week 2 - Multivariate Linear Regression