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!

animuson
  • 53,861
  • 28
  • 137
  • 147
Sevros
  • 157
  • 1
  • 10

2 Answers2

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.

Tony Allevato
  • 6,429
  • 1
  • 29
  • 34
  • 1
    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. – JRomero Dec 01 '13 at 15:16
  • Oops, yes, you're correct, thanks for catching that. I've updated the answer. – Tony Allevato Dec 01 '13 at 15:23
  • 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? – ptc Mar 10 '14 at 03:49
  • @ptc 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. – LongZheng Mar 25 '14 at 14:24
  • 1
    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. – LongZheng May 15 '14 at 13:28
  • @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 ? – Sheraz Ahmad Khilji Sep 10 '14 at 08:05
  • You should be able to use an to achieve this. http://developer.android.com/guide/topics/manifest/activity-alias-element.html – Tony Allevato Sep 10 '14 at 15:33
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);
lgvalle
  • 31
  • 1