Android Question OK Google Call or Search of App

shaffnert03

Member
Licensed User
As noted in http://android-developers.blogspot.com/2014/10/the-fastest-route-between-voice-search.html, the "OK Google" hotword detection now built into Android can link automatically to an app. Is there a way to do this in B4A? I want to be able to have a user say "OK Google" followed by commands specific to my app and get a voice response. I've been searching the forums for "Search Action" or anything else I can think of that might be related, all to no avail so far. How can I link this up?

https://developers.google.com/voice-actions/system/ also discusses approaches for this. Any help or guidance would be appreciated!
 

Erel

Administrator
Staff member
Licensed User
Complete example:
B4X:
Sub Process_Globals
   Private prevIntent As Intent
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
End Sub

Sub Activity_Resume
   Dim in As Intent = Activity.GetStartingIntent
   If in.IsInitialized And in <> prevIntent Then
     Log(in)
     Log(in.ExtrasToString)
     prevIntent = in
     If in.Action = "com.google.android.gms.actions.CREATE_NOTE" Then
       Msgbox(in.GetExtra("android.intent.extra.TEXT"), "Taking note")
     End If
   End If
End Sub
Manifest:
B4X:
AddActivityText(main,  <intent-filter>
  <action android:name="com.google.android.gms.actions.CREATE_NOTE" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:mimeType="*/*" />
  </intent-filter>
)
Now say Ok Google take a note one two three.
 

shaffnert03

Member
Licensed User
Thanks Erel. One question though. Isn't this just leveraging the built in note taking voice command? As in, this approach doesn't enable me to create my own command, does it?

What I'm looking for would be something to allow the user to say:

"OK Google, ask <App Name> for <App-Specific Action or Result>" and to get as a spoken voice response the result of a function or sub in my app.

The above solution could sort of do this as long as I triggered off the "take a note" keyword, but it wouldn't use my app name and it would break the normal OK Google note taking response for all my users. Is there a way to create a customized version of this?
 

shaffnert03

Member
Licensed User
Frankly, I'm not sure what that page is saying. It says "Google Voice Actions allows you to define custom actions to support use cases not addressed by system actions" at the top and then at the bottom says "Note: We are not accepting requests for Custom Voice Actions." Not exactly a clear message is it....

That said, https://developers.google.com/voice-actions/interaction/voice-interactions looks like it's for how to build such an action.

Erel, you've likely read a lot more of this documentation than I have; do you have a sense of what they're actually saying? Can you tell if it's possible?
 

klarsys

Active Member
Licensed User
Very interesting post. I wish "OK Google, ask <App Name> for/to <App-Specific Action or Result>" was supported by Google.... :rolleyes:
 

George Popovic

Member
Licensed User
I copied this from Google Chrome using Windows 10. I also tried to copy the code to Notepad first, then to code and got the same result.
 

Rusty

Well-Known Member
Licensed User
Did anyone get this "OK Google" to work?
If so, how did you manage this? I'm using B4a v8.8...
Thanks in advance.
Rusty
 

ocalle

Active Member
Licensed User
Rusty i found this example from Utheh to use lights


expect be useful
 

Rusty

Well-Known Member
Licensed User
Thanks Ocalle!
What I was looking for was a way to "listen" constantly like the Amazon Alexa or "OK Google" where you don't have to touch a button to be heard. That way a speaker could be across the room or away from the phone/tablet/device and be able to say a key phrase to cause the device to take some action.
Rusty
 
Top