Android 轻“.NET研究”松实现语音识别
苹果的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,上海闵行企业网站制作r /> * WITHOUT WARRANTIE上海企业网站制作S 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) {
上海网站建设yle="color: #0000ff;">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 );
上海闵行企业网站设计与制作='color:white;' href='http://www.93tj.com'>上海徐汇企业网站制作 sp上海企业网站设计与制作eakButton.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_it上海徐汇企业网站设计与制作em_1,
matches));
}
super .onActivityResult(requestCode, resultCode, data);
}
}
Tip:本篇 从Api Demo直接复制过来,必须有网络支持。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
世界博览:“谷歌”地球共和国?,互联网营销
核心提示:我们以谢尔盖·布林的一段话来展望Google 与互联网时代的未来。他说:“当我还是个小孩子的时候,想学点什么东西,要跑很远去当地的图书馆,如果运气好,才能找到一本感兴趣的书。在不久的将来,人们可以在数秒之内协作完成专业研究。当今世界经济还是乌云笼罩,对我们所有人来说都是一段相当困难的时期。但等到今天的孩子们长大时,这次衰退只不过是历史上的一个脚印,而我们一直以来所创造的技术将决定未来。” 刚刚过去的情人节那天,生活在硅谷的华裔软件工程师赵先生邀请妻子来到屋后的花园里,他一手牵着她的手,另一只手中握着手机。夜空中挂满窃窃私语的星斗,赵先生对准星空拍了几张照片,只见手机屏幕上显示出相应的星座名称。 “我太太当时吃惊得说不出话来!”人们虽然已经习惯了手机应用越来越智能化,但很少有人想象得到——Google的一项创新性应用能使手机拥有一只具有识别信息能力的“魔眼”。 2009年12月7日,Google公司发布了手机搜索应用“Google Goggles”,即“视觉搜索”,用户使用Android操作系统的手机拍摄照片即可搜索相关信息,这让搜索引擎向真正的智能化迈上了一个新台阶。 现在G...
- 下一篇
洞察移动互联网的未来,互联网营销
随着全球3G网络和无线城市的日趋成熟,移动互联网将面临新的机遇与挑战。移动互联网是移动通信和互联网技术结合的产物,被称为革命性的通信技术。它的发展成熟将改变人们传统的沟通方式。移动互联网并不是互联网业务向移动通信业务的简单移植,融合后所催生新应用才是移动互联网发展的未来。传统的电信业务已经不能满足人们日益增长的需要,以数据为核心的新型业务将逐渐渗透到移动互联网方方面面。另外,传统互联网上的应用服务也不一定适合移动互联网。终端和使用习惯等诸多因素影响下,移动互联网会催生更多个性化的应用。 移动互联网的未来将主要体现在以下七大方面: 一、 电子阅读:移动互联网的新契机 电子阅读已经成为继移动音乐之后最具潜力的增值业务,阅读市场甚至可能具有比移动音乐更大的发展空间。2009年5月,相关调研数据显示,中国用户平时使用手机上网内容型业务时,对图书的需求占44%,排在首位。电子阅读业务,已经在海外有了成功案例。据国外媒体报道,经过10年的发展,电子阅读已经让一些国外企业开始进入收获期。Amazon亚马逊2008年一共售出50万部Kindle电子阅读器。远远高于之前预期的38万部。去年7到9月,21...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS6,CentOS7官方镜像安装Oracle11G
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- SpringBoot2全家桶,快速入门学习开发网站教程
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- MySQL8.0.19开启GTID主从同步CentOS8