Create "ok glass" style menu, within glass app
Asked Answered
D

4

8

I have just begun developing for Google Glass, and I knew the GDK if fairly new so this may not be possible yet, but here's what I'm trying to to:

As with the "make a call" prompt or the "send a message to" prompts on the "okay glass" screen, I would like my app to have more voice selected options when you select it with your voice. With the two examples, you will see a list of contacts, which you can nod your head up and down to see more of, and the app will only take further actions one you've selected one of the displayed choices. Is there currently any way to do that on my own app?

Any input is appreciated!

Decapitate answered 24/11, 2013 at 19:44 Comment(2)
I'm also looking for this... for those who are still unclear, you can see it in such apps as the built in camera app. When you take a picture or video via voice command, you are given an "ok glass" option within context of the picture or video you have just taken. This would be extremely useful for any app to take advantage of.Hippodrome
This is a duplicate of another question and Alain answered that it is not possible yet in the GDK and to file a feature request: https://mcmap.net/q/1192565/-adding-the-quot-ok-glass-contextual-voice-menu-quot-within-an-immersion-activityKenelm
T
2

You can call an intent to display the Voice Recognizer after your Activity has started. So, you could have your voice trigger and prompt from the launch, and then, in your Activity's onResume(), call the Voice Recognizer, with some kind of prompt (or you could just string the initial speech collected into this as the prompt):

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra( RecognizerIntent.EXTRA_PROMPT, "ok glass, here's my prompt" );
    startActivityForResult(intent, 0);

You then would need an onActivityResult() method to process the return form the VoiceRecognizer.

This is the described in the GDK docs: https://developers.google.com/glass/develop/gdk/input/voice

Not sure if there is any other way.

Terrorstricken answered 25/11, 2013 at 3:43 Comment(2)
I've tried this, and it works to an extent, but it still isn't the kind of menu I'm looking for. This way the text the user is saying will replace the prompt as they start speaking, and they can say anything here. Instead I only want the glass to act if they say one of my actions. Guess that isn't possible yet...Decapitate
I have tried this approach, but found that it only works when you have an active internet connection. From the documentation: "The implementation of this API is likely to stream audio to remote servers to perform speech recognition which can use a substantial amount of bandwidth."Infuscate
R
2

I found this answer from another SO question that seems exactly like you want. I have tried it myself for my own Glassware and it works perfectly. As mentioned in the answer below, one caveat that other apps that use the same "ok glass" voice command will share the submenu; in the following example, for instance, some other app may add other games such as "golf." Another potential problem is that you must have an Activity or Service for each of the options you want in the submenu.

"If you have multiple activities/services installed on Glass that have the same voice trigger intent filter, all of their names (based on the android:label attribute of the <activity> or <service> tag in AndroidManifest.xml) will appear in a disambiguation "submenu" when you speak that voice trigger.

For example (assume that res/xml/play_a_game_trigger.xml represents a voice trigger for the string "play a game"):

<activity android:label="Tennis">
    <intent-filter>
        <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
    </intent-filter>
    <meta-data android:name="com.google.android.glass.VoiceTrigger"
        android:resource="@xml/play_a_game_trigger" />
</activity>
<activity android:label="Bowling">
    <intent-filter>
        <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
    </intent-filter>
    <meta-data android:name="com.google.android.glass.VoiceTrigger"
        android:resource="@xml/play_a_game_trigger" />
</activity>

would give you a voice menu flow that looks like

ok glass → play a game → Tennis
                         Bowling

Do note, however, that this menu would also include activities/services from other APKs that use the same voice trigger as well.

You can find more details at the Voice Input page of the GDK documentation."

Recognition answered 3/1, 2014 at 7:8 Comment(0)
A
0

Are you asking if you can add a voice command to Glass that will trigger your app? If so - absolutely. This is, in fact, the suggested way to start an app on the GDK.

See https://developers.google.com/glass/develop/gdk/input/voice#launching_glassware for the details, but basically you'll

  1. Add resources to res/values/strings.xml describing the trigger and prompt
  2. Create a resource in res/xml/<my_voice_trigger>.xml that uses the string value as the keyword and sets the input prompt
  3. Register an intent filter for the VOICE_TRIGGER action

(As an aside, it appears that verbs are the best voice triggers to use - they flow more naturally with the "ok, glass" menu item.)

Alvaalvan answered 24/11, 2013 at 21:49 Comment(1)
Yes I know how to do that, but I'm asking AFTER I've selected my app if there is a way to present another menu that acts much like the "ok google" menu, but with my custom options.Decapitate
S
0

Now you can use framework apis to show an ok glass menu on your activity, check this Docs about contextual voice commands

https://developers.google.com/glass/develop/gdk/voice#contextual_voice_commands

Shaun answered 2/7, 2014 at 12:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.