苹果的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 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 matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
mList.setAdapter(new ArrayAdapter(this, Android.R.layout.simple_list_item_1,
matches));
}
super.onActivityResult(requestCode, resultCode, data);
}
}
本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011-09/43068.htm
所以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 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 matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
mList.setAdapter(new ArrayAdapter(this, Android.R.layout.simple_list_item_1,
matches));
}
super.onActivityResult(requestCode, resultCode, data);
}
}
本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011-09/43068.htm
发表评论
-
Android开发 单例模式导致内存泄露
2012-09-17 15:52 8062存在内存泄露问题的一些代码片段像下面这样: ... -
Android 处理内存泄露的方法
2011-11-01 12:15 1563. 内容 本文档包含如下内容: l 如何确定App ... -
RatingBar 不可点击
2011-11-01 09:32 17224UI: <RatingBar android:id=& ... -
解决ListView拖动时背景黑色的问题
2011-10-31 15:03 1004Android为我们提供了ListView 的多种实现方法,通 ... -
Android 内存优化小结
2011-10-31 08:45 1017根据我个人的开发经验总结了如下几点优化内存的方法: 1、创建 ... -
Android性能优化
2011-10-29 21:00 917● 首先内存方面,可以参考 Android堆内存也可自己定义 ... -
Android Animation学习笔记
2011-10-13 13:22 785关于动画的实现,Android ... -
AndroidManifest.xml文件解析
2011-10-12 08:40 777一、关于AndroidManifest.xml Androi ... -
Android 注册广播两种方式区别
2011-10-11 17:06 1015BroadcastReceiver用于监听被广播的事件 必须 ... -
Android 横竖屏切换 activity变化详解
2011-10-11 16:53 1364生命周期 Android 系统在Activity 生命周期中加 ... -
Activity 的生命周期 以及 横屏竖屏切换时 Activity 的状态变化
2011-10-11 16:50 940生命周期 Android 系统在Activity 生命周期中加 ... -
了解 uri, content provide,包括 data android:host,android:scheme(转)
2011-10-08 11:11 1029了解 uri, content provide,包括 data ... -
Android中TextView内容过长加省略号
2011-09-21 09:52 1332textview中有个内容过长加省略号的属性,即ellipsi ... -
Android 定位慢的解决方法
2011-09-20 17:37 870Android的官方文档给出了推荐的方案: 首先注册自己的 ... -
Android 按钮事件弹出多个对话框
2011-09-20 13:20 3758最近发现,在对按钮添加单击事件监听,在监听事件中弹出一个对话框 ... -
Android 图标旋转
2011-09-19 14:31 3489最近在做地图应用开发,遇到在获取到“我的位置”之后,需要画一个 ...
相关推荐
Android 轻松实现语音识别的完整代码,很实用,希望对你有帮助!!
Android语音识别软件代码 调用系统的语音控件进行语音识别代码。
Android语音识别源码
Android中主要通过RecognizerIntent来实现语音识别,其实代码比较简单,但是如果找不到语音识别设备,就会抛出异常 ActivityNotFoundException,所以我们需要捕捉这个异常。而且语音识别在模拟器上是无法测试的,...
代码是简单的语音识别demo,使用的是科大讯飞的api,想看的同学可以看看。
结合demo实现Android语音识别功能,只需一些简洁的代码即可实现语音识别功能,里面的demo可以直接运行,简单。
本程序是在Android系统下实现语音识别功能,借用Android系统提供的类完成语音识别功能,java代码
语音现在已经成为了一种信息,移动开发者不得不看的安卓语音识别的源码!
三个android语音识别例程mystt.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
android语音识别,android语音搜索,调用androidAPI实现。代码注释详细。
android语音识别代码 ,详细地内容请参考我的博客:http://blog.csdn.net/vipa1888/article/details/7023928
Android实例源码-语音识别&文本朗读类安卓源代码(6例) ...三个android语音识别例程mystt 语音合成和语音听写,科大讯飞,代码有详细注释 语音识别,根据语音,执行对应操作 调用安卓自带文本朗读
android系统下,语音识别的源代码,可供大家学习参考使用。
qt实现科大讯飞在线语音识别功能,可以实现语音文字的转换。
Android项目源码大全的160套源代码资源,这里是其中的获轻松实现语音识别源码,大家一起学习交流哈!
本例子是一个微信语音的例子源码,微信语音开放平台致力于为开发者提供免费的语音技术,目前已经开放的语音技术包括在线语音识别、在线语音合成等。语音识别功能已经在微信上使用并获好评无数,提高了聊天输入效率,...
语音识别在android上使用起来很方便也很简单.但是有个前提条件,就是android机器上必须预先安装google的语音搜索工具,今天我们就来详细探讨下