Tuesday 4 July 2017

How to integrate "Google Voice" into your android app

Google Voice | OK Google | Google Now

What is google voice action ?

This is separate from the search-by-voice functionality provided by Google Voice Search.
The concept is relatively simple: the user makes a request on Google Now ranging from “Take a picture” to “Play Thriller on myMusicApp”, and Android will open any app that is able to handle that specific request.

How google voice action work?
It recognizes your voice and converts it into the text or takes the appropriate action.
 Voice recognition feature can be achieved by RecognizerIntent.

Available Google Voice action are 
  • Set an alarm for 7 am (Alarm)
  • Set a timer for 5 minutes (Alarm)
  • Call Bosco (Communication)
  • Take a picture (Media)
  • Record a video (Media)
  • Play thriller on myMusicApp (Media)
  • Search for cat videos on MyApp (Search)
  • Open google.com (Web Browser)
How Google Voice Action Integrate in our App ?
  
      Step  1 : Update Gradle Build to Android M:
               android {

                            compileSdkVersion 23
                            buildToolsVersion "23.0.1"

                            defaultConfig {
                                                   minSdkVersion 23
                                                   targetSdkVersion 23
                           }
               }   

       
      Step 2 : Set up an Intent Filter in the Manifest to receive the voice intent 
                      from Google Now:For “Take a picture”:  

             <intent-filter>            <action android:name="android.media.action.STILL_IMAGE_CAMERA"/>            <category android:name="android.intent.category.DEFAULT"/>            <category android:name="android.intent.category.VOICE"/>           </intent-filter>


          For Searching

              <intent-filter>
              <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
              <category android:name="android.intent.category.DEFAULT"/>
              <category android:name="android.intent.category.VOICE"/>
             </intent-filter>

       Step 3 : Check for voice interaction:

           if (!isVoiceInteractionRoot() || !isVoiceInteraction()) {               //Not a voice interaction, proceed normally                 } else {                            beginVoiceInteraction();                     }          

             Alternatively, if your voice interaction includes a search query:
            Here get text from voice as search query.

             String action = intent.getAction();             if (action.equals(Intent.ACTION_SEARCH)) {                String query = intent.getStringExtra(SearchManager.QUERY);                 handleVoiceQuery(query);             }


               
             

      - You can find more Here about google voice action.
     

No comments:

Post a Comment