2019独角兽企业重金招聘Python工程师标准>>>

【转自:老枪】

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

所以Google Voice Recognition在Android 的实现就变得极其轻松。 
 
语音识别,借助于云端技术可以识别用户的语音输入,包括语音控制等技术,下面我们将利用Google 提供的Api 实现这一功能。

功能点为:通过用户语音将用户输入的语音识别出来,并打印在列表上。

功能界面如下: 
 
用户通过点击speak按钮显示界面: 
 
用户说完话后,将提交到云端搜索: 
 
在云端搜索完成后,返回打印数据: 

标签: Android 语音识别 Android SDK

代码片段(1)[全屏查看所有代码]

1. [代码]Android 轻松实现语音识别的完整代码

001 * Copyright (C) 2008 The Android Open Source Project
002 *
003 * Licensed under the Apache License, Version 2.0 (the "License");
004 * you may not use this file except in compliance with the License.
005 * You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software
010 * distributed under the License is distributed on an "AS IS" BASIS,
011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 * See the License for the specific language governing permissions and
013 * limitations under the License.
014 */
015
016 package com.example.android.apis.app;
017
018 import com.example.android.apis.R;
019
020 import android.app.Activity;
021 import android.content.Intent;
022 import android.content.pm.PackageManager;
023 import android.content.pm.ResolveInfo;
024 import android.os.Bundle;
025 import android.speech.RecognizerIntent;
026 import android.view.View;
027 import android.view.View.OnClickListener;
028 import android.widget.ArrayAdapter;
029 import android.widget.Button;
030 import android.widget.ListView;
031
032 import java.util.ArrayList;
033 import java.util.List;
034
035 /**
036 * Sample code that invokes the speech recognition intent API.
037 */
038 public class VoiceRecognition extends Activity implements OnClickListener {
039
040 private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
041
042 private ListView mList;
043
044 /**
045 * Called with the activity is first created.
046 */
047 @Override
048 public void onCreate(Bundle savedInstanceState) {
049 super.onCreate(savedInstanceState);
050
051 // Inflate our UI from its XML layout description.
052 setContentView(R.layout.voice_recognition);
053
054 // Get display items for later interaction
055 Button speakButton = (Button) findViewById(R.id.btn_speak);
056
057 mList = (ListView) findViewById(R.id.list);
058
059 // Check to see if a recognition activity is present
060 PackageManager pm = getPackageManager();
061 List activities = pm.queryIntentActivities(
062 new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
063 if (activities.size() != 0) {
064 speakButton.setOnClickListener(this);
065 else {
066 speakButton.setEnabled(false);
067 speakButton.setText("Recognizer not present");
068 }
069 }
070
071 /**
072 * Handle the click on the start recognition button.
073 */
074 public void onClick(View v) {
075 if (v.getId() == R.id.btn_speak) {
076 startVoiceRecognitionActivity();
077 }
078 }
079
080 /**
081 * Fire an intent to start the speech recognition activity.
082 */
083 private void startVoiceRecognitionActivity() {
084 Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
085 intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
086 RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
087 intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
088 startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
089 }
090
091 /**
092 * Handle the results from the recognition activity.
093 */
094 @Override
095 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
096 if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
097 // Fill the list view with the strings the recognizer thought it could have heard
098 ArrayList matches = data.getStringArrayListExtra(
099 RecognizerIntent.EXTRA_RESULTS);
100 mList.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,
101 matches));
102 }
103
104 super.onActivityResult(requestCode, resultCode, data);
105 }
106 }

转载于:https://my.oschina.net/u/1467940/blog/208667

【转】Android 轻松实现语音识别相关推荐

  1. Android轻松实现语音识别

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

  2. Android 轻松实现语音识别详解及实例代码

    使用Intent调用语音识别程序 说明 Android中主要通过RecognizerIntent来实现语音识别,其实代码比较简单,但是如果找不到语音识别设备,就会抛出异常 ActivityNotFou ...

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

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

  4. Android 轻松实现仿淘宝地区选择

    代码地址如下: http://www.demodashi.com/demo/11122.html 一.准备工作 Android开发环境,学习Android的童鞋肯定都知道了,这里我就不累述了. 二.运 ...

  5. Android轻松实现日期选择器、生日选择器、自定义起始时间

    前言 Android轻松实现日期选择器.生日选择器.自定义起始时间 废话不多说 看下效果 效果图 代码实现 代码实现比较简单 按照步骤 你也可以实现同样的效果 第一步 设置依赖 android 和an ...

  6. android运动轨迹怎么画,Android轻松画出触摸轨迹

    本文实例介绍了Android如何画出触摸轨迹的方法,分享给大家供大家参考,具体内容如下 效果图: 实现代码: package com.android.gameview5; import android ...

  7. Android开发之语音识别

    Android开发之语音识别 开发背景 RecognizerIntent相关知识 代码解释 完整代码 项目运行及问题解决 开发背景 最近了解了一下Android Q(安卓10),得知Android Q ...

  8. Android集成百度语音识别到HelloWorld需要注意什么?(保姆级教学)

    Android集成百度语音识别怎么避坑? 首先先放一张集成失败的图(记得一定要用真机,因为它不支持VAD,我这里使用Pixel2): 首先你去百度搜索"百度语音识别",或者点击我下 ...

  9. android悬浮窗语音识别demo

    带有android悬浮窗的语音识别语义理解demo 如发现代码排版问题,请访问CSDN博客 Android桌面悬浮窗实现比较简单,本篇以一个语音识别,语义理解的demo来演示如何实现android悬浮 ...

最新文章

  1. mysql ERROR 1045
  2. 使用LM2576制作数控电源
  3. 【读书笔记】基础博弈知识小结
  4. ospf协议_三级网络技术考前选择题3—OSPF协议
  5. jquery事件 on(),live(),delegate(),blind()
  6. com.microsoft.sqlserver.jdbc.SQLServerException: 索引 7 超出范围。
  7. npm上传自己的项目
  8. Jmeter之JDBC Request与mysql
  9. nginx服务器能ping通,访问不了的解决办法
  10. 解决办法:RuntimeError: module compiled against API version 0xc but this version of numpy is 0xa
  11. C语言函数的声明、定义、调用
  12. CRITIC权重指标如何计算?
  13. ffmpeg 快速截图m3u8图片
  14. 软件工程(系统流程图讲解)
  15. 利用一个竞态漏洞root三星s8的方法
  16. 字体图标在服务器上显示不出来,fontawesome图标字体库组件在服务器上显示不出来图标的解决...
  17. BZOJ4372: 烁烁的游戏(动态点分治)
  18. 解决Win2003 IIS不能下载rmvb
  19. 《途客圈创业记:不疯魔,不成活》一一2.4 与iWeekend再续前缘
  20. Nuxt3接入51la等网站统计

热门文章

  1. Java条件查询分页——总结
  2. Spring aop 记录操作日志 Aspect 自定义注解
  3. Redis详解——常用命令总结(完善中)
  4. private、protected、public、published 访问限制(或者叫类成员的可见性)
  5. webpack打包---报错内存溢出javaScript heap out of memory
  6. (十)HTTP协议【前后端分离的时代,网络请求是前端的生命线】
  7. 软件测试反例,基于模型检测多反例对软件进行调试
  8. 台式计算机防盗锁怎么安装,防盗门锁怎么拆装 防盗门锁拆装步骤【详细介绍】...
  9. bootstrap算法_决策树算法之随机森林
  10. Spring Boot集成Debezium监控数据库变化