自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android輕松實(shí)現(xiàn)語(yǔ)音識(shí)別

移動(dòng)開(kāi)發(fā) Android
iphone好像永遠(yuǎn)都在和Android相比較,本文是Android系統(tǒng)的語(yǔ)音識(shí)別。

蘋(píng)果的iphone 有語(yǔ)音識(shí)別用的是Google 的技術(shù),做為Google 力推的Android 自然會(huì)將其核心技術(shù)往Android 系統(tǒng)里面植入,并結(jié)合google 的云端技術(shù)將其發(fā)揚(yáng)光大。

所以Google Voice Recognition在Android 的實(shí)現(xiàn)就變得極其輕松。

[[31167]]

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

功能點(diǎn)為:通過(guò)用戶語(yǔ)音將用戶輸入的語(yǔ)音識(shí)別出來(lái),并打印在列表上。

功能界面如下:

用戶通過(guò)點(diǎn)擊speak按鈕顯示界面:

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

在云端搜索完成后,返回打印數(shù)據(jù):

 

#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 目錄結(jié)構(gòu)分析

Android應(yīng)用程序開(kāi)發(fā)環(huán)境的搭建

在Android應(yīng)用程序中使用Internet數(shù)據(jù)

責(zé)任編輯:zhaolei 來(lái)源: 網(wǎng)絡(luò)轉(zhuǎn)載
相關(guān)推薦

2012-07-10 13:29:30

Java

2015-12-07 14:39:18

微軟Windows 95語(yǔ)音識(shí)別

2012-07-25 13:23:32

ibmdw

2017-01-06 13:12:11

AndroidRecyclerVie懸浮條

2016-02-17 10:39:18

語(yǔ)音識(shí)別語(yǔ)音合成語(yǔ)音交互

2022-09-26 11:35:50

App開(kāi)發(fā)技術(shù)框架Speech框架

2009-08-21 15:28:23

C#英文

2011-01-18 11:52:25

Linux語(yǔ)音識(shí)別

2021-05-06 11:13:06

人工智能語(yǔ)音識(shí)別

2021-05-06 11:18:23

人工智能語(yǔ)音識(shí)別

2009-07-21 15:28:06

Windows Emb

2021-12-24 10:34:11

鴻蒙HarmonyOS應(yīng)用

2022-12-01 07:03:22

語(yǔ)音識(shí)別人工智能技術(shù)

2017-02-27 21:37:49

2017-10-27 16:19:23

語(yǔ)音識(shí)別CNN

2021-11-17 10:37:39

語(yǔ)音識(shí)別技術(shù)人工智能

2019-10-12 17:42:33

2015-10-23 13:41:20

android源碼科大訊飛語(yǔ)音識(shí)別

2017-03-20 10:14:03

語(yǔ)音識(shí)別匹配算法模型

2024-01-08 19:30:15

AI開(kāi)源語(yǔ)音識(shí)別
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)