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

匿名 (未验证) 提交于 2019-12-03 02:47:02

问题:

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!

回答1:

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.



回答2:

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); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!