1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question OK Google Call or Search of App

Discussion in 'Android Questions' started by shaffnert03, Dec 23, 2015.

  1. shaffnert03

    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!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Complete example:
    Code:
    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:
    Code:
    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.
     
    MarkusR likes this.
  3. shaffnert03

    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?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Peter Simpson likes this.
  5. shaffnert03

    shaffnert03 Member Licensed User

    Ahh, thank you, I think that's the answer I was really looking for.

    To be clear, they're not supported by B4A though, right? Because https://developers.google.com/voice-actions/custom-actions would seem to imply they are supported by Google (though it's not very helpful in discussing how). Any idea when they will be supported?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    shaffnert03 likes this.
  7. shaffnert03

    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?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    shaffnert03 likes this.
  9. klarsys

    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:
     
  10. George Popovic

    George Popovic Member Licensed User

    Why do I get this when I copy and paste the above example into a new program?


    Errors.png
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload the project (File - export as zip)?
     
  12. George Popovic

    George Popovic Member Licensed User

    As Requested, see attached project file...
     

    Attached Files:

  13. Erel

    Erel Administrator Staff Member Licensed User

    Which browser were you using when you copied the text? It converted the spaces to 0xa0 code points:

    [​IMG]
     
  14. George Popovic

    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.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    Test it with a different browser.
     
  16. Rusty

    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
     
  17. ocalle

    ocalle Active Member Licensed User

    Rusty i found this example from Utheh to use lights



    expect be useful
     
  18. Rusty

    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
     
    ocalle likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice