Google Glass未列出的内容语音命令无法正常运行

时间:2015-04-24 07:59:28

标签: java android google-glass

我对识别未列出的语音命令有疑问。我无法使用语音命令启动应用程序"ok glass" - >像我期望的那样"Test"。但我可以使用“ok glass”在我的应用程序中调用菜单。所有3个菜单项都会正确显示菜单,但说"rotate""free rotate""stop rotate"不会产生任何影响。我认为识别未列出的命令有问题,但我不明白。有什么建议?我也想知道从菜单项到语音触发器的连接是如何发生的,因为菜单项只知道String.xml的字符串?使用触摸条控制菜单工作正常。

的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(只是重要内容的摘录)

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

2 个答案:

答案 0 :(得分:1)

我尝试了一些语音命令,这是我发现的:

  1. “测试”似乎不起作用。另一方面,用小写的第一个字母“测试”确实有效。这似乎只会影响某些单词,因为我已经能够成功使用“Next”作为触发器。
  2. 将字符串资源“Stop Rotate”更改为“stop_rotate”。

答案 1 :(得分:0)

在我的情况下,当我将Glass连接到Wifi时,问题就解决了。代码中没有进行其他更改。感谢Flupp。