How to implement the Android Speech Recognition service Interface Recognitionservice

Source: Internet
Author: User

A previous article introduced the SpeechRecognizer class, which can be used as an external interface, and pass a componentname through intent to obtain a service that supports speech recognition, if some software for speech recognition is installed in a general user's phone, will have this ability, but if developers want to integrate their own speech recognition services through a company's SDK, they need to implement the Recognitionservice class.

This class is an abstract class that requires a developer to complete several of these abstract methods. Each method is described in the following code comment.

<pre name= "code" class= "Java" >public class Bdrecognitionservice extends Recognitionservice {       @Override    public void OnCreate () {        super.oncreate ();        Once the service is invoked    @Override    protected void onstartlistening (Intent recognizerintent, Callback mcallback) {      //This method specifically implements the third-party SDK access,//recognizerintent carries the upper layer of the parameters//mcallback need to be the third-party SDK results callback to the interface, is the upper layer and the third-party SDK Bridge} @Override protected void OnCancel (Callback listener) {//logoff} @Override public void OnDestroy () {//Destroy Super.ondestroy ();} @Overrid e protected void onstoplistening (Callback listener) {//pause}}

The callback interface has the following several

public class Callback {private final irecognitionlistener mlistener;        Private Callback (Irecognitionlistener listener) {Mlistener = listener; } public void Beginningofspeech () throws RemoteException {if (DBG) log.d (TAG, "BEGINNINGOFSPEEC            H ");        Mlistener.onbeginningofspeech ();         } public void bufferreceived (byte[] buffer) throws RemoteException {mlistener.onbufferreceived (buffer); The public void error (int error) throws RemoteException {Message.obtain (Mhandler, Msg_res            ET). Sendtotarget ();        Mlistener.onerror (Error); } public void Partialresults (Bundle partialresults) throws RemoteException {MLISTENER.ONPARTIALR        Esults (Partialresults); } public void Readyforspeech (Bundle params) throws remoteexception {Mlistener.onreadyforspeech (P        Arams); } public void results (Bundle results) Throws RemoteException {Message.obtain (Mhandler, Msg_reset). Sendtotarget ();        Mlistener.onresults (results);        } public void rmschanged (float rmsdb) throws RemoteException {mlistener.onrmschanged (RMSDB); }    }

An article will then show the service code that implements the Baidu speech recognition SDK.


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.