久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2514|回復(fù): 0
收起左側(cè)

Android 輕松實(shí)現(xiàn)語音識別的完整代碼

[復(fù)制鏈接]
ID:57113 發(fā)表于 2013-11-21 14:48 | 顯示全部樓層 |閱讀模式
* 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
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
}


轉(zhuǎn)載:http://www.armboard.org/forum.php?mod=viewthread&tid=102&extra=page%3D1
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 亚洲国产欧美国产综合一区 | 精精精精xxxx免费视频 | 日中文字幕在线 | 国产精品一区二区三区在线 | 人人爱干 | 在线观看视频你懂得 | 九色国产| 伊人性伊人情综合网 | 国产高清免费 | 国产精品爱久久久久久久 | 久久久亚洲 | 黄色大片在线 | 播放一级毛片 | 91国内精精品久久久久久婷婷 | 国产一区二区在线视频 | 国产一级在线 | 澳门永久av免费网站 | 久久www免费人成看片高清 | 午夜精品久久 | 日韩一区二区三区四区五区六区 | 天堂中文在线播放 | 成人福利在线观看 | 午夜欧美 | 久久久一二三 | 日本三级在线网站 | 日本污视频 | 亚洲+变态+欧美+另类+精品 | 欧美成人精品二区三区99精品 | 国产精品久久久久久久久久免费看 | 国产日产精品一区二区三区四区 | 久久久久成人精品 | 华丽的挑战在线观看 | 久久午夜电影 | 国产一区二区三区 | 亚洲系列第一页 | 亚洲 欧美 综合 | 理论片午午伦夜理片影院 | 三级av在线 | 黄色在线免费看 | 国产高清一二三区 | 亚洲成人免费观看 |