Question Detail

There are numerous instructional exercises online for adding voice recognition to an Android application. They are frequently confusing and the distributers of the coding are never accessible for questions. I require a straightforward exercise with complete coding for adding voice recognition to my application and Describe everything about what happening because I don't have any idea what is the internal logic for this. 
Image result for voice recognition


Thread Reply

Anonymous

- 1 years ago

Google Voice Actions recognizes many spoken and typed action requests and creates Android intents for them. Apps like Play Music and Keep can receive these intents and perform the requested action. Your app can declare support for some of these actions too:

  1. Define an intent filter
  2. Handle the intent in your app
  3. Update your app completion status

For a detailed list of supported system actions, see System Actions Reference.

Step 1: Define an intent filter

To indicate that your app supports one or more system actions, include an intent filter for each action in the manifest file of your app.

For example, if your app can set an alarm, add the following intent filter to your manifest file:


 

<activity ...>
    <intent-filter>
        <action android:name="android.intent.action.SET_ALARM"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

If a user has multiple apps that can handle the Set an Alarm intent, Google Voice Actions lets them choose the app to complete the action:

Image showing Google voice actions invoking an app

Figure 1: Voice Actions lets users select from apps that support system actions.

 

Step 2: Handle the intent in your app

When your app receives the intent, it should perform the action. In this example, it should set the alarm. See the code example below.

Step 3: Update your app completion status

The App Indexing API allows you to send completed app activities to Google. Google can then surface your content to users again later, via query autocompletion from the Google app.

After your app performs the action, call the AppIndexApi.end() method with an appropriate action type, for example Action.TYPE_ADD.

You should also set the appropriate action status type to report whether the action was completed successfully or not. You can use the setActionStatus method to set the status for a particular action.

Here's a complete example demonstrating how to handle the incoming intent and use the App Indexing API to report that the user successfully set an alarm:


 

public class MainActivity extends Activity {

    private static final Uri ALARM_URI = Uri.parse("android-app://com.myclockapp/set_alarm_page");

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...

        // Get the intent
        Intent intent = getIntent();
        if (AlarmClock.ACTION_SET_ALARM.equals(intent.getAction())) {
            if (intent.hasExtra(AlarmClock.EXTRA_HOUR)) {
                // Step 2: get the rest of the intent extras and set an alarm
                ...
            }

            // Step 3: report the action through the App Indexing API
            Thing alarm = new Thing.Builder()
                    .setName("Alarm for 4:00 PM")
                    .setDescription("Alarm set for 4:00 PM, with the 'Argon' ringtone"
                                    + " and vibrate turned on.")
                    .setUrl(APP_URI)
                    .build();

            Action setAlarmAction = new Action.Builder(Action.TYPE_ADD)
                    .setObject(alarm)
                    .setActionStatus(Action.STATUS_TYPE_COMPLETED)
                    .build();

            AppIndex.AppIndexApi.end(mClient, setAlarmAction);
        }
    }

    ...

}

System actions reference

Google Voice Actions fires an intent when it recognizes any of the actions listed in the following tables.

Alarm actions

Action Example Command
Set alarm set an alarm for 6 am
Set timer set a timer for 5 minutes

Communication actions

Action Example Command
Initiate a phone call call 555-5555
call Starbucks
call mom
call voicemail

The Call actions only trigger on devices with a built-in dialer (like a phone) and on devices with apps that support dialing (like a tablet with a VoIP app).

Fitness actions

Action Example Command
Start/stop a bike ride start a bike ride
Start/stop a run start a run
Start/stop a workout start a workout
Show heart rate show heart rate
Show step count show step count

Local actions

Action Example Command
Book a cab book a cab

The Book a cab action only triggers on Android Wear.

Media actions

Action Example Command
Play music from search play michael jackson billie jean
play some music
play classical music
play off the wall
play pink Floyd on vnstreamer
Take a picture take a picture
Record a video record a video

Open actions

Action Example Command
Open URL open twitter.com
Open Application open twitter (Works by default; no specific intent.)

Productivity actions

Action Example Command
Take a note take a note buy groceries

Search actions

Action Example Command
Search using a specific app search for cat videos on youtube

https://developers.google.com/voice-actions/system/