Way to nest multiple voice triggers when launching an app with GDK
Asked Answered
K

2

10

Is there a way to nest voice triggers when launching an app on Google Glass using the GDK? For example instead of just saying "ok, glass" -> "What's its power level?" I'd like to have the app present an option. For example "ok, glass" -> "What's its power level?" -> "Over 9000" OR "Under 9000". Any help would be great!

Karilynn answered 21/11, 2013 at 6:11 Comment(0)
W
13

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.

Wonderstricken answered 21/11, 2013 at 15:43 Comment(7)
Shouldn't android:name="Bowling" be android:label="Bowling"? I'm sure it falls back to activity name but label should be the appropriate attribute.Thrifty
Oops, yes, you're correct, thanks for catching that. I've updated the answer.Wonderstricken
When I use this approach the top-level app item ("Play a game") in the "ok glass" tap menu does not display an icon. However, once I tap the "Play a game" item, the submenu items ("Tennis", "Bowling") have icons. Anyone have a solution to get an app-wide icon in the menu?Lumbricalis
@Lumbricalis I think the reason for this is because Google thinks your app's voice trigger has a label clash with another app, so the top-level menu does not show the icon of any app, then the submenu items show the app's icon.Antakiya
I believe this behavior no longer works under XE17.1. Deploying a GDK app with this, the "Home" menu crashes when tapped using the touchpad (it doesn't load the app menu). The "OK Glass" voice command still works.Antakiya
@TonyAllevato What if both of these "bowling" and "Tennis" belong to the same activity ? Android doesn't allow us to declare the activity name twice in the manifest ?Item
You should be able to use an <activity-alias> to achieve this. developer.android.com/guide/topics/manifest/…Wonderstricken
G
3

The proper way to do this is using an input tag inside the trigger

<trigger keyword="@string/start_app" >

    <input prompt="@string/promt_text" />

</trigger>

This prompts an input and waits for more audio speech.

Then in your activity you can capture this text with:

ArrayList<String> text = getIntent().getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
Goosegog answered 29/11, 2013 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.