2

I have a problem with the recognition of unlisted Voice Commands. I can't start the app by using the Voice Command "ok glass" -> "Test" like I would expect. But I can call the menu in my app by using "ok glass". The menu is displayed properly with all 3 menu items, but saying "rotate", "free rotate", "stop rotate" doesn't effect anything. I think there is something wrong with the recognition of unlisted commands, but I don't get it. Any suggestions? I also wonder how the connection from the menu item to the voice trigger happens, because the menu item only knows the strings of String.xml? Controlling the menu with the touch strip works fine.

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blah.stl3dviewer" >
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission
    android:name="com.google.android.glass.permission.DEVELOPMENT" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.DeviceDefault" >
    <activity
        android:name=".STLViewportActivity"
        android:icon="@drawable/ic_glass_logo"
        android:label="@string/app_name" >
        <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/voice_trigger" />

    </activity>
</application>
</manifest>

Menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/rotate_menu_item"
    android:title="@string/glass_rotate_trigger"
    />
<item
    android:id="@+id/freerotate_menu_item"
    android:title="@string/glass_freerotate_trigger"
    />
<item
    android:id="@+id/stoprotate_menu_item"
    android:title="@string/glass_stoprotate_trigger"
    />
</menu>

String.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Test</string>
<string name="title_activity_stlviewport">STL Viewport</string>
<string name="glass_rotate_trigger">Rotate</string>
<string name="glass_stoprotate_trigger">Stop Rotate</string>
<string name="glass_freerotate_trigger">Free Rotate</string>
</resources>

rotate_voice_trigger.xml

<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_rotate_trigger" />

freerotate_voice_trigger.xml

<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_freerotate_trigger" />

stoprotate_voice_trigger.xml

<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_stoprotate_trigger" />

voice_trigger.xml

<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/app_name" />

STLViewportActivity.java (just an excerpt with the important stuff)

public class STLViewportActivity extends Activity {

@Override
protected void onCreate(Bundle bundle) {
    //...
    getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);
    //...
}
@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
    if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS
                || featureId == Window.FEATURE_OPTIONS_PANEL) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }
    return super.onCreatePanelMenu(featureId, menu);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS
            || featureId == Window.FEATURE_OPTIONS_PANEL) {
        switch (item.getItemId()) {
            case R.id.rotate_menu_item:
                openglViewport.getRenderer().setAutoRotate();
                break;
            case R.id.stoprotate_menu_item:
                openglViewport.getRenderer().setNoRotate();
                break;
            case R.id.freerotate_menu_item:
                openglViewport.getRenderer().setFreeRotate();
                break;
            default:
                return true;
        }
        return true;
    }
    return super.onMenuItemSelected(featureId, item);
}
}
Flupp
  • 856
  • 10
  • 24
  • 1
    For now I can't find what is wrong with your code but I can tell you for sure that in your xml directory the only useful xml is voice_trigger.xml. The Glass recognize the voice command directly in the menu.xml by reading android:title. voice_trigger.xml instead tells the Glass OS in the manifest that can be started by the "ok glass" outside the app. – Cloud57 Apr 24 '15 at 09:27
  • That's good to know, I already wondered how the parsing of the contextual command works. But the calling of my app via "ok glass" -> "Test" doesn't work either, pending on that problem since a few days now. – Flupp Apr 24 '15 at 09:52
  • Can you try adding in your activity in the manifest: – Cloud57 Apr 24 '15 at 12:35
  • @Cloud57: That didn't effect anything. – Flupp Apr 24 '15 at 13:48
  • @Flupp can you post your final version of relevant files that work now? – Rohan Jul 29 '15 at 04:59
  • I didn't change anything of my source, like I already mentioned in the accepted answer: It was just the lack of the internet connection. If it doesn't work for you, the accepted answer below provides some workaround, that I had to use sometimes. – Flupp Oct 12 '15 at 15:01

2 Answers2

1

I tried some of the voice commands and here's what I found:

  1. "Test" does not seem to work. "test" with the lower case first letter, on the other hand, does work. It seems like this only affects certain words since I've been able to use "Next" as a trigger successfully.
  2. Changing the string resource "Stop Rotate" to "stop_rotate" works.
Koh
  • 1,570
  • 1
  • 8
  • 6
  • 1
    Thanks for your answer. I changed it to your suggestion but still didn't work. Now I know why, because Glass needs an internet connection for it. And since I connected it, everything works smoothly. – Flupp May 22 '15 at 08:30
0

In my case the problem get solved when I connected the Glass to the Wifi. No additional changes made in code. Thanks to Flupp.

Gökhan Kurt
  • 531
  • 5
  • 13