成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android輕松實現語音識別

移動開發 Android
iphone好像永遠都在和Android相比較,本文是Android系統的語音識別。

蘋果的iphone 有語音識別用的是Google 的技術,做為Google 力推的Android 自然會將其核心技術往Android 系統里面植入,并結合google 的云端技術將其發揚光大。

所以Google Voice Recognition在Android 的實現就變得極其輕松。

[[31167]]

語音識別,借助于云端技術可以識別用戶的語音輸入,包括語音控制等技術,下面我們將利用Google 提供的Api 實現這一功能。

功能點為:通過用戶語音將用戶輸入的語音識別出來,并打印在列表上。

功能界面如下:

用戶通過點擊speak按鈕顯示界面:

用戶說完話后,將提交到云端搜索:

在云端搜索完成后,返回打印數據:

 

#p#

完整的代碼如下:

  1. /*   
  2.  * Copyright (C) 2008 The Android Open Source Project  
  3.  *  
  4.  * Licensed under the Apache License, Version 2.0 (the "License");  
  5.  * you may not use this file except in compliance with the License.  
  6.  * You may obtain a copy of the License at  
  7.  *  
  8.  *      http://www.apache.org/licenses/LICENSE-2.0  
  9.  *  
  10.  * Unless required by applicable law or agreed to in writing, software  
  11.  * distributed under the License is distributed on an "AS IS" BASIS,  
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13.  * See the License for the specific language governing permissions and  
  14.  * limitations under the License.  
  15.  */  
  16. package com.example.android.apis.app;  
  17. import com.example.android.apis.R;  
  18. import android.app.Activity;  
  19. import android.content.Intent;  
  20. import android.content.pm.PackageManager;  
  21. import android.content.pm.ResolveInfo;  
  22. import android.os.Bundle;  
  23. import android.speech.RecognizerIntent;  
  24. import android.view.View;  
  25. import android.view.View.OnClickListener;  
  26. import android.widget.ArrayAdapter;  
  27. import android.widget.Button;  
  28. import android.widget.ListView;  
  29. import java.util.ArrayList;  
  30. import java.util.List;  
  31. /**  
  32.  * Sample code that invokes the speech recognition intent API.  
  33.  */  
  34. public class VoiceRecognition extends Activity implements OnClickListener {     
  35.     private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;  
  36.       
  37.     private ListView mList;  
  38.  
  39.     /**  
  40.      * Called with the activity is first created.  
  41.      */  
  42.     @Override  
  43.     public void onCreate(Bundle savedInstanceState) {  
  44.         super.onCreate(savedInstanceState);  
  45.  
  46.         // Inflate our UI from its XML layout description.  
  47.         setContentView(R.layout.voice_recognition);  
  48.  
  49.         // Get display items for later interaction  
  50.         Button speakButton = (Button) findViewById(R.id.btn_speak);  
  51.           
  52.         mList = (ListView) findViewById(R.id.list);  
  53.  
  54.         // Check to see if a recognition activity is present  
  55.         PackageManager pm = getPackageManager();  
  56.         List<ResolveInfo> activities = pm.queryIntentActivities(  
  57.                 new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);  
  58.         if (activities.size() != 0) {  
  59.             speakButton.setOnClickListener(this);  
  60.         } else {  
  61.             speakButton.setEnabled(false);  
  62.             speakButton.setText("Recognizer not present");  
  63.         }  
  64.     }  
  65.     /**  
  66.      * Handle the click on the start recognition button.  
  67.      */  
  68.     public void onClick(View v) {  
  69.         if (v.getId() == R.id.btn_speak) {  
  70.             startVoiceRecognitionActivity();  
  71.         }  
  72.     }  
  73.     /**  
  74.      * Fire an intent to start the speech recognition activity.  
  75.      */  
  76.     private void startVoiceRecognitionActivity() {  
  77.         Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);  
  78.         intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,  
  79.                 RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);  
  80.         intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");  
  81.         startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);  
  82.     }  
  83.     /**  
  84.      * Handle the results from the recognition activity.  
  85.      */  
  86.     @Override  
  87.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  88.         if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {  
  89.             // Fill the list view with the strings the recognizer thought it could have heard  
  90.             ArrayList<String> matches = data.getStringArrayListExtra(  
  91.                     RecognizerIntent.EXTRA_RESULTS);  
  92.             mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,  
  93.                     matches));  
  94.         }  
  95.         super.onActivityResult(requestCode, resultCode, data);  
  96.     }  

【編輯推薦】

Android 廣播接收者

Android 目錄結構分析

Android應用程序開發環境的搭建

在Android應用程序中使用Internet數據

責任編輯:zhaolei 來源: 網絡轉載
相關推薦

2012-07-10 13:29:30

Java

2015-12-07 14:39:18

微軟Windows 95語音識別

2012-07-25 13:23:32

ibmdw

2017-01-06 13:12:11

AndroidRecyclerVie懸浮條

2016-02-17 10:39:18

語音識別語音合成語音交互

2022-09-26 11:35:50

App開發技術框架Speech框架

2025-06-27 05:00:00

AI語音詐騙AI語音識別人工智能

2009-08-21 15:28:23

C#英文

2021-05-06 11:18:23

人工智能語音識別

2021-05-06 11:13:06

人工智能語音識別

2011-01-18 11:52:25

Linux語音識別

2009-07-21 15:28:06

Windows Emb

2021-12-24 10:34:11

鴻蒙HarmonyOS應用

2022-12-01 07:03:22

語音識別人工智能技術

2010-07-16 10:31:02

Batch Telne

2021-11-17 10:37:39

語音識別技術人工智能

2019-10-12 17:42:33

2017-10-27 16:19:23

語音識別CNN

2015-10-23 13:41:20

android源碼科大訊飛語音識別

2024-01-08 19:30:15

AI開源語音識別
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 伊人久久免费 | 蜜桃综合在线 | 黄色毛片网站在线观看 | 亚洲精品在线观 | 日韩视频免费看 | 久久免费视频观看 | 久草在线青青草 | 在线国产小视频 | 亚洲不卡一| 3p视频在线观看 | 亚洲欧美综合精品久久成人 | 亚洲 欧美 另类 综合 偷拍 | 国产亚洲一区二区三区 | 中文字幕亚洲欧美 | 视频1区 | 亚洲成人天堂 | 一区二区视频在线 | 精品久久久久国产免费第一页 | 亚洲视频欧美视频 | 久久成人国产 | 91精品国产一区二区三区 | 久久久精彩视频 | 在线观看中文字幕 | 日韩欧美亚洲一区 | 午夜视频在线观看网址 | 中文字幕在线视频免费观看 | 国产免费一区二区 | 91资源在线播放 | 黄色一级大片在线免费看产 | 欧美综合国产精品久久丁香 | 日本高清不卡视频 | 在线观看成人 | 婷婷久久网 | 亚洲伦理自拍 | 日韩精品一区二区三区 | 亚洲精品片 | 日本免费一区二区三区四区 | 久久久精品综合 | 精品欧美在线观看 | 亚洲精品www | 中文字幕在线精品 |