0

I am developing an app where user can speak the command and it will get executed. Just like "Voice Search" app from Google. I want to use set of commands associated actions of Voice Search.

My code is as follows:

@Override
public void startVoiceRecognitionActivity() {
    // TODO Auto-generated method stub
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Command me");
    startActivityForResult(intent, REQUEST_CODE);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case REQUEST_CODE: {
            ArrayList<String> matches = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            ApplicationDebug.printlog("got inside onactivityresult");
            String spokenText = matches.get(0);
            Toast.makeText(getApplicationContext(), spokenText,
                    Toast.LENGTH_LONG).show();
            // super.onActivityResult(requestCode, resultCode, data);
            break;
        }
    }
}

on some button click I am calling startVoiceRecognitionActivity().

It is detecting the voice correctly but the action is not happening here. What I mean exactly is if I say "Open Calculator", it shows the text correctly, but does not open calculator app.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sameer Kulkarni
  • 186
  • 3
  • 8
  • 1
    You'll have to develop your own matching logic. That is, when `spokenText` is equal to `open calculator`, open the calculator app. Speech recognition is just transcription from voice to text, it's not interpreting it, even less carrying out any action based on that interpretation. – Alexis Pigeon Sep 09 '14 at 13:45
  • thanks for your reply. is there any api from google voice search app which i can use directly so that i can get actions they are using? – Sameer Kulkarni Sep 09 '14 at 13:59
  • 2
    I can't say for sure, but I really doubt it. – Alexis Pigeon Sep 09 '14 at 14:01
  • thanks @AlexisPigeon. It seems like i need to build the whole engine i guess. – Sameer Kulkarni Sep 09 '14 at 14:03

1 Answers1

0

Sounds like you're looking for this:

RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE

Joe Austin
  • 557
  • 7
  • 24