2

Hello I want build an app where my android app recognize my voice command & perform certain task. i have searched a lot but didn't find any valid solution. Kindly tell how to implement it?

Tarun Sharma
  • 601
  • 3
  • 13
  • 31

1 Answers1

3

you may take a look at this question if you want offline speech recognition:

But there is also a another solution:

You can use this app which is made by google a few years ago. just install this app in your device and then simply call that app :

private void startRecognizeSpeech() {

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

    try {
        startActivityForResult(intent, RESULT_SPEECH);

    } catch (ActivityNotFoundException a) {
        Toast.makeText(
                getApplicationContext(),
                "Oops! First you must download \"Voice Search\" App from Store",
                Toast.LENGTH_SHORT).show();
    }
}

Then in onActivityResult() do this :

@Override
// calls when voice recognition result received
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case RESULT_SPEECH: {
        if (resultCode == RESULT_OK && null != data) {
            // text is received form google
            ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
 //you can find your result in text Arraylist  
        }
        break;
    }
 }
}
Community
  • 1
  • 1
Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
  • What if i don't want to use google now.or any other installed app – Tarun Sharma Feb 25 '15 at 12:57
  • 1
    I've searched a little and unfortunately haven't find any other app. I just found some of googles apps. You can also use this library http://cmusphinx.sourceforge.net/wiki/tutorialandroid . thats an offline and open source voice recognition library – Milad Faridnia Feb 25 '15 at 13:09