Android Speech Recognition (code in other materials)

Source: Internet
Author: User

Today I saw a Simple Speech Recognition book.CodeNow, just copy it and make a simple note, in case you can't find any information when you need to search for it. I also hope that my friends who need to study in this area will pay attention to it. The code is read from the book. As for the name of the book, it will not be written, so there will be no suspicion of advertising!

The Code is as follows:

Code

    Try  {
Intent intent = New Intent (
Recognizerintent. action_recognize_speech );
Intent. putextra (recognizerintent. extra_language_model,
Recognizerintent. language_model_free_form );
Intent. putextra (recognizerintent. extra_prompt, " Enable voice " );

Startactivityforresult (intent, speechrequest );
} Catch (Exception e ){
Toast. maketext (speechrecognitiontest. This , E. getmessage (),
Toast. length_long). Show ();
}

}

 

If you want to process the returned code, you need to rewrite the write handler. The Code is as follows:

 

Code

  @ Override
Protected Void Onactivityresult ( Int Requestcode, Int Resultcode,
Intent intent ){
// Self-uploaded requestcode
// Result Status returned by resultcode
// Todo auto-generated method stub
If (Speechrequest = Requestcode && Resultcode = Result_ OK ){
Toast. maketext (speechrecognitiontest. This , " The returned result is normal. " ,
Toast. length_long). Show ();
Arraylist < String > Result = Intent. getstringarraylistextra (recognizerintent. extra_results ); // Obtains the characters of a language.

// If it is a page, you can update it to one column per letter on the page.
// Listview Lv = new listview (null );
//
// LV. setadapter (New arrayadapter <string> (this, R. layout. Main, result ));

String resultstring = "" ;
// String
For ( Int I = 0 ; I < Result. Size (); I ++ )
{
Resultstring + = Result. Get (I );
}
}
Super . Onactivityresult (requestcode, resultcode, intent );
}

 

You can use the above method to display the voice! Of course, if you want to deal with and identify other aspects, you can also view the relevant information. Here is a simple introduction.

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.