Android 轻松实现语音识别
苹果的iphone 有语音识别用的是Google 的技术,做为Google 力推的Android 自然会将其核心技术往Android 系统里面植入,并结合google 的云端技术将其发扬光大。
所以Google Voice Recognition在Android 的实现就变得极其轻松。
语音识别,借助于云端技术可以识别用户的语音输入,包括语音控制等技术,下面我们将利用Google 提供的Api 实现这一功能。
功能点为:通过用户语音将用户输入的语音识别出来,并打印在列表上。
功能界面如下:
用户通过点击speak按钮显示界面:
用户说完话后,将提交到云端搜索:
在云端搜索完成后,返回打印数据:
完整代码如下:
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.app;
import com.example.android.apis.R;
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.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
/**
* Sample code that invokes the speech recognition intent API.
*/
public class VoiceRecognition extends Activity implements OnClickListener {
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234 ;
private ListView mList;
/**
* Called with the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
// Inflate our UI from its XML layout description.
setContentView(R.layout.voice_recognition);
// Get display items for later interaction
Button speakButton = (Button) findViewById(R.id.btn_speak);
mList = (ListView) findViewById(R.id.list);
// 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 ) {
speakButton.setOnClickListener( this );
} else {
speakButton.setEnabled( false );
speakButton.setText( " Recognizer not present " );
}
}
/**
* Handle the click on the start recognition button.
*/
public void onClick(View v) {
if (v.getId() == R.id.btn_speak) {
startVoiceRecognitionActivity();
}
}
/**
* Fire an intent to start the speech recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, " Speech recognition demo " );
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
@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);
mList.setAdapter( new ArrayAdapter < String > ( this , android.R.layout.simple_list_item_1,
matches));
}
super .onActivityResult(requestCode, resultCode, data);
}
}
Tip:本篇 从Api Demo直接复制过来,必须有网络支持。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
使用 MNIST 图像识别数据集
下载代码示例 机器学习领域中最迷人的主题之一是图像识别 (IR)。使用红外系统的示例包括使用指纹或视网膜识别的计算机登录程序和机场安全系统的扫描乘客脸寻找某种通缉名单上的个人。MNIST 数据集是可用于实验的简单图像集合沙用红外的算法。这篇文章并介绍了一个相对简单 C# 程序,向您介绍的 MNIST 数据集,这反过来你接触到红外的概念。 它不太可能你会需要使用红外大多数软件应用程序,但我觉得你可能有用的信息在这篇文章为四个不同的原因。第一,没有更好的方法,了解的 MNIST 数据集和 IR 概念比通过试验与实际的代码。第二,有一个基本的理解的红外将帮助您了解的功能和真实的、 先进的红外系统的限制。第三,在这篇文章中解释的编程技术的几个可用于不同的、 更常见的任务。第四,你就会找到红外有趣的在其自己的权利。 看到这篇文章去哪儿的最佳方法是要看一看在演示程序图 1。演示计划是一个经典的 Windows 窗体应用程序。标签为加载图像的按钮控件读入内存称为MNIST 的数据集的标准图像识别数据集。数据集包含的 60,000 手写体数字从 0 到 9,已经数码化。演示了作为一位映射的图像显示当...
- 下一篇
会编程的 AI + 会修 Bug 的 AI,等于什么 ?
2017-02-25 Python开发者 (点击上方公众号,可快速关注) 关于人工智能未来的畅想,除了家庭服务机器人,快递无人机,医用机器人等等,Lucas Carlson 认为人工智能在另外一个领域的可能带来的变革,却没有引起公众的足够注意——这就是:让计算机自己编程。 2016年11月末,Lucas Carlson 撰文: 目前,机器学习方面的专家倾向于把研究聚焦于具体领域内高度裁剪的 AI 应用——比如:面部识别、自动驾驶汽车、语音识别,甚至是互联网搜索结果等方面。但是,这些技术同样可以应用到让计算机理解其自身的代码架构上——当然这里是指脱离人类的帮助、解释和干涉的情况下进行的理解——其实这种对代码的“理解”和让计算机理解自然语言,或是识别图像并没有本质的区别。 如果代码能够自我分析——做到比人类更快地修正错误并不断优化——那么技术革新将会发生得越来越快。其带来的可能性几乎是无穷无尽的:医学上的进步,更智能的机器人,更“智能“的手机等等。 ……而 AI 将会改变这种局面。 Lucas的全文,请参见《让代码写代码,自主编程的 AI 离我们还有多远?》(http://blog.job...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS8编译安装MySQL8.0.19
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Red5直播服务器,属于Java语言的直播服务器
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- CentOS6,CentOS7官方镜像安装Oracle11G
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装