1

i need your help im developing a speech recognition app, which performs actions such as making a call, sending a message and the familiar stuff.. i managed to program the voice recognition in my app and it works great, but i cant seem to understand how to perform these actions, for example if i tell the app "call michael" , how is it done in coding? how to write calling action\sms action in code? i would really appreciate any help!

here is a code that describes how i get the word action from speech recognition:

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        //check speech recognition result 
        if (requestCode == VOICE_REC_CODE_REQUEST && resultCode == RESULT_OK) 
        {
            //store the returned word list as an ArrayList
            ArrayList<String> suggestedWords= data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            startExecutingActions(suggestedWords);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

the question is, how do i execute these actions\commands like; call, send sms, search the web, navigate and more, and use them in startExecutingActions(suggestedWords) function?

Lena
  • 71
  • 7
  • You should fire an intent with the right action: http://developer.android.com/reference/android/content/Intent.html – Bram Feb 01 '16 at 14:56

2 Answers2

2

In the given example of calling someone you will need to start a new intent with a phone action. Here is a list of common intents.

Let's say you recognized that the user want's to call a specific number (by looking up the name in your phonebook). Then you can call your "dialNumber" method with the phone number.

public void dialNumber(String pNumber){

    Intent intent = new Intent(Intent.ACTION_PHONE);
    intent.setData(Uri.parse("tel:" + pNumber));
    if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivity(intent);
    };
}

You will need to make sure that your app has all the required permissions in your AndroidManifest.xml.

Alexander Hoffmann
  • 5,104
  • 3
  • 17
  • 23
  • thanks for the answer, do i have to find the number every time the user asks for a new contact, or is there a way that the code would find the contact from the contacts list and then call or sms the contact? – Lena Feb 01 '16 at 15:11
1

Add this code:

if (!suggestedWords.isEmpty()) {
   if (suggestedWords.get(0).contains("call michael")) {
      //Get michael contact phone number
      //Call michael
   }
}

If you want to get contact phone number, use this


If you want to call, use this

Community
  • 1
  • 1
Volodymyr Kulyk
  • 6,455
  • 3
  • 36
  • 63