android开发分享Android实现语音识别代码

苹果的iphone 有语音识别用的是google 的技术,做为google 力推的android 自然会将其核心技术往android 系统里面植入,并结合google 的云

苹果的iphone 有语音识别用的是google 的技术,做为google 力推的android 自然会将其核心技术往android 系统里面植入,并结合google 的云端技术将其发扬光大。 所以google voice recognition在android 的实现就变得极其轻松。

上述就是android开发分享Android实现语音识别代码的全部内容,如果对大家有所用处且需要了解更多关于Android学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

Android实现语音识别代码 

语音识别,借助于云端技术可以识别用户的语音输入,包括语音控制等技术,下面我们将利用google 提供的api 实现这一功能。 功能点为:通过用户语音将用户输入的语音识别出来,并打印在列表上。 功能界面如下:

Android实现语音识别代码 

用户通过点击speak按钮显示界面:

Android实现语音识别代码

用户说完话后,将提交到云端搜索:

Android实现语音识别代码

在云端搜索完成后,返回打印数据:

Android实现语音识别代码

  * 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  *  * https://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);  }  }

以上所述就是android开发分享Android实现语音识别代码的全部内容了,希望大家能够喜欢。

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/addevelopment/941153.html

(0)
上一篇 2021年11月14日
下一篇 2021年11月14日

精彩推荐