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.