过程如下:

1、启动语音识别 Activity

2、这里处理语音(传到 google 服务器处理)

3、结果以 Acitivity 的结果返回(onActivityResult)

主要用到的类为 android.speech.RecognizerIntent

package com.linc;  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.Button;  import android.widget.TextView;  public class VoiceRecognitionDemoActivity extends Activity {  private static final String TAG = "VoiceRecognition";  private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;  private TextView textView;  private Button button;  @Override  public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.main);  initWidget();  // Check to see if a recognition activity is present  PackageManager pm = getPackageManager();  List<ResolveInfo> activities = pm.queryIntentActivities(  new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);  if (activities.size() != 0) {  button.setOnClickListener(new OnClickListener() {  @Override  public void onClick(View v) {  startVoiceRecognitionActivity();  }  });  } else {  button.setEnabled(false);  button.setText("Recognizer not present");  }  }  private void initWidget()  {  textView = (TextView)findViewById(R.id.tv);  button = (Button)findViewById(R.id.btn);  }  /** * Fire an intent to start the speech recognition activity. */  private void startVoiceRecognitionActivity() {  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);  // Display an hint to the user about what he should say.  intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "请说标准普通话");//注意不要硬编码  // Given an hint to the recognizer about what the user is going to say  intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,  RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);  // Specify how many results you want to receive. The results will be sorted  // where the first result is the one with   higher confidence.  intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);//通常情况下,第一个结果是最准确的。  startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);  }  @Override  protected 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);  StringBuilder stringBuilder = new StringBuilder();  int Size = matches.size();   for(int i=0;i<Size;++i)  {  stringBuilder.append(matches.get(i));  stringBuilder.append("\n");  }  textView.setText(stringBuilder);  }  super.onActivityResult(requestCode, resultCode, data);  }  }  

最后说明:在国内是使用必须要使用手机VPN翻墙,否则无法使用。

RecognizerIntent(语音识别)相关推荐

  1. 安卓语音识别(RecognizerIntent)

    今天在csdn网站上突然找到安卓语音识别功能感觉不错,结合其它博主和关于安卓语音识别的书籍来编写如下(若有侵犯,请立即告诉我) 话不多说直接进入主题: Android主要通过自带的Recognizer ...

  2. Android初学者之轻松实现语音识别

    Android初学者之轻松实现语音识别 苹果的iphone有语音识别用的是Google的技术,做为Google力推的Android 自然会将其核心技术往Android 系统里面植入,并结合google ...

  3. webrtc 语音流java_通过WebView WebRTC从麦克风传输语音时的语音识别

    我正在编写一个具有WebView的应用程序,它通过WebRTC处理语音呼叫 . 麦克风工作正常,因为我已授予WebView权限 . webView.setWebChromeClient(new Web ...

  4. Android利用RecognizerIntent识别语音并简单实现打电话动作

    关于Android利用RecognizerIntent识别语音并简单实现打电话,具体看实现代码如下: package com.example.recognizerintentactivity;impo ...

  5. 【转】Android 轻松实现语音识别

    2019独角兽企业重金招聘Python工程师标准>>> [转自:老枪] 苹果的iphone 有语音识别用的是Google 的技术,做为Google 力推的Android 自然会将其核 ...

  6. android远程linux命令,测试可用的Android远程语音识别实例

    测试可用的Android远程语音识别实例: 代码下载在: 相关文件下载在Linux公社的1号FTP服务器里,下载地址: 用户名:www.linuxidc.com 密码:www.muu.cc 在 201 ...

  7. android语音识别开源代码,android语音识别,有没有相应的源码,教程可以推荐啊?

    一. 系统内置语音识别 try { final Locale locale = Locale.getDefault(); String language = String.format("% ...

  8. Android实现语音识别代码

    苹果的iphone 有语音识别用的是Google 的技术,做为Google 力推的Android 自然会将其核心技术往Android 系统里面植入,并结合google 的云端技术将其发扬光大. 所以G ...

  9. Android语音识别(本地+第三方)

    语音识别主要的功能就是在用户不方便输入的时候找一个替代输入的选择. 1.本地语音识别 下面的代码首先创建SpeechRecognizer对象,并设置回调函数监听器.当在点击监听器中调用doSpeech ...

最新文章

  1. 微信小程序插件功能页开发详细流程
  2. 十佳自由Linux物理工具
  3. 有人说 GPT3 是“暴力美学”的结晶,它的工作原理你知道吗?| 动图详解
  4. 网格弹簧质点系统模拟(Spring-Mass System by Verlet Integration)附源码
  5. IDEA 每次运行项目时都提示源值1.5已过时,将在未来所有版本中删除
  6. PAT-A Sign In and Sign Out
  7. SVG可伸缩的矢量图形
  8. jxl.read.biff.BiffException: Unable to recognize OLE stream解决方法
  9. JavaWEB二十:Ajax Axios框架
  10. 软件测试方法——静态测试与动态测试
  11. C语言——打鱼晒网问题
  12. JavaWeb的学习(上)
  13. perf part II
  14. c语言stdoux串口流,嵌入式C语言代码优化的一些经验
  15. Java实验三 Java继承、抽象类与接口(13题)
  16. Spring Boot中使用Convert接口实现类型转换器
  17. unity AudioToolkit 音频工具包的简介+使用方法
  18. Android无法播放本地视频
  19. 试解PTA《20211122-函数基础练习》,涉及 高精度加法 和 10进制转换成2-16进制问题,有需要的同学来看看吧;
  20. 【webpack】webpack 入门教程

热门文章

  1. 转载——三种编程命名规范(匈牙利命名法、驼峰式命名法、帕斯卡命名法)...
  2. linux 网络有关的5个命令
  3. poj-1201 Intervals(差分约束)
  4. Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(二)
  5. NodeJS无所不能:细数10个令人惊讶的NodeJS开源项目
  6. SQL日期与时间函数
  7. 8-1-Filter过滤器
  8. 如何用openweather显示html,如何显示openweathermap天气图标
  9. php mysql查询出来二叉树的数据_tp框架怎么实现二叉树查询 如图,查询数据库中小明下面的所有人。到底下面多少人,不清楚。 代码如何实现...
  10. centos ifconfig命令找不到_测试需要掌握docker的一些基本命令