Overview of using the Android speech recognition feature

Source: Internet
Author: User

Android has introduced support for speech recognition. Speech recognition is mainly located in the Android.speech package, the main classes include SpeechRecognizer, Recognitionservice, Recognizerintent, Recognizerresultsintent, Classes and interfaces such as Recognitionlistener.

SpeechRecognizer provides an interface to access speech recognition services, the following are common methods of SpeechRecognizer :

<span style= "FONT-SIZE:18PX;" >  Createspeechrecognizer ()/    /Create a speech recognizer        Setrecognitionlistener ()    //Set Listener        startlistening ()    //Start speech recognition        stoplistening ()    //End speech recognition </span>

Speech recognition requires the "Android.permission.RECORD_AUDIO" permission.

In order to make speech recognition, it is necessary to publish a speech recognition activity, then the speech recognition engine will be started, and the user's voice will be processed, the result of processing is returned through the Onactivityresult () method. Here's an implementation in Android:

SpeechRecognizer sr = Speechrecognizer.createspeechrecognizer (this, new ComponentName (Getpackagename (),                BDRecognitionService.class.getName ()));        Sr.setrecognitionlistener (New Listener ());        Sr.startlistening (New Intent (Getintent (). Getaction ()). Putextras (Getintent ()));

callback method

<span style= "TEXT-INDENT:24PX; BACKGROUND-COLOR:RGB (240, 240, 240); " >class Listener implements recognitionlistener{</span> @Override public void Onreadyforspeech (Bundl e params) {} @Override public void Onbeginningofspeech () {} @ Override public void onrmschanged (float rmsdb) {} @Override public void Onbufferr        Eceived (byte[] buffer) {} @Override public void Onendofspeech () {} @Override public void OnError (int. error) {} @Override public void on Results (Bundle Results) {//specific process recognition result} @Override public void Onpartialresults ( Bundle partialresults) {} @Override public void onEvent (int eventtype, bundle params) {}}


Note: Although Android provides this interface, it does not provide specific recognition capabilities

New ComponentName (Getpackagename (),BDRecognitionService.class.getName ())

As a result, the parameters at the time of instantiation specify the service that implements the function, which requires the developer to implement the Recognitionservice interface, and the next article will describe how to implement the class.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.