Android - Voice Recognition API

Project description

Abstract (fr): Dans ce projet, une API de Reconnaissance de la Voix a été développée, en
utilisant le classe publique RecognizerIntent. Pour que la reconnaissance soit effectuée
l'application doit avoir des permissions d’accès sur Internet. Les résultats sont retournes
par la méthode onActivityResult et l'utilisateur peut choisir parmi une liste les nombres des réponses correspondant a son requête.

Abstract (en): In this project a Voice Recognition API was developed using
RecognizerIntent public class. In order for voice recognition to be performed application
must be provided with Internet access permissions. Results are returned by
onActivityResult method and the user may select through an index the number of responses he will get.

Android 4.2.2 - API level 17
IDE Eclipse Juno v21.0.0
Emulator for the original compilation: Samsung GT-15500
You can download the project here

You can use this application by connecting to your GooglePlay account and installing in your mobile one of the many apk management utilities.

Note:
The application should look like the image below. But if your mobile has access rights to the Internet instead of the "Voice recognizer not present" assigned to the button, which is obviously inactive you should get the message "Speak" and you should be able to press the button.






MainActivity Examples



//Method to Toast the message
void showToastMessage(String message){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}



public void checkVoiceRecognition() {
// Checks if  Voice recognition is available
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() == 0) {
mbtSpeak.setEnabled(false);
mbtSpeak.setText("Voice recognizer not present");
Toast.makeText(this, "Voice recognizer not present",
Toast.LENGTH_SHORT).show();
       }


public void speak(View view) {
 Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// Specifies the calling package to identify your application.
 intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass()
 .getPackage().getName());


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE)
//If Voice recognition is successful then it returns RESULT_OK
if(resultCode == RESULT_OK) {

ArrayList<String> textMatchList = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

if (!textMatchList.isEmpty()) {
// If first match contains the "search" word
// Then start a web search
if (textMatchList.get(0).contains("search")) {

String searchQuery = textMatchList.get(0);
searchQuery = searchQuery.replace("search","");
Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
search.putExtra(SearchManager.QUERY, searchQuery);
startActivity(search);
} else {
// populate the Matches
mlvTextMatches
.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
textMatchList));

----------------------------------------------------------------------------------



No comments:

Post a Comment


Free online chess

View Kapellas Nick's profile on LinkedIn
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License