Glass 语音命令给定列表中最接近的匹配项

2024-05-18

使用 Glass,您可以通过“确定,Glass”菜单启动应用程序,它似乎会选择最接近的匹配项,除非命令相距数英里,并且您可以明显看到命令列表。
无论如何,是否可以从应用程序内或从语音提示(在初始应用程序触发后)给出类似的列表并返回最接近的匹配项。

随机(非现实世界)示例,一个显示颜色的应用程序,“OK Glass,显示红色”

“显示颜色”可能是您的语音触发器,并且似乎与“最近邻居”方法上的玻璃相匹配,但是“红色”只是作为自由文本读入,很容易被误听为“恐惧”或“头”,甚至“读”,因为无法区分“读”和“红色”。

有没有办法将预先批准的选项列表(红色、绿色、蓝色、橙色*等)传递到此阶段,或传递到应用程序内的另一个语音提示,以便用户可以查看列表并获得更准确的结果当有一组有限的预期响应时(例如主好的玻璃屏幕)?

*好吧,没有什么与橙色押韵的,我们在那里可能很安全


Google GDK 尚不支持此功能。然而,一些库中已经提供了必要的功能,只要 GDK 本身不支持,您就可以使用它们。 你必须做什么:

  1. 从 Glass 中提取 GlassVoice.apk:adb pull /system/app/GlassVoice.apk

  2. 使用 dex2jar 将此 apk 转换为 jar 文件。

  3. 将 jar 文件添加到您的构建路径

现在你可以像这样使用这个库:

public class VoiceActivity extends Activity {

    private VoiceInputHelper mVoiceInputHelper;
    private VoiceConfig mVoiceConfig;

        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.voice_activity);

        String[] items = {"red", "green", "blue", "orange"};
        mVoiceConfig = new VoiceConfig("MyVoiceConfig", items);
        mVoiceInputHelper = new VoiceInputHelper(this, new MyVoiceListener(mVoiceConfig),
                VoiceInputHelper.newUserActivityObserver(this));
    }

    @Override
    protected void onResume() {
        super.onResume();
        mVoiceInputHelper.addVoiceServiceListener();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mVoiceInputHelper.removeVoiceServiceListener();
    }

    public class MyVoiceListener implements VoiceListener {
        protected final VoiceConfig voiceConfig;

        public MyVoiceListener(VoiceConfig voiceConfig) {
            this.voiceConfig = voiceConfig;
        }

        @Override
        public void onVoiceServiceConnected() {
            mVoiceInputHelper.setVoiceConfig(mVoiceConfig, false);
        }

        @Override
        public void onVoiceServiceDisconnected() {

        }

        @Override
        public VoiceConfig onVoiceCommand(VoiceCommand vc) {
            String recognizedStr = vc.getLiteral();
            Log.i("VoiceActivity", "Recognized text: "+recognizedStr);

            return voiceConfig;
        }

        @Override
        public FormattingLogger getLogger() {
            return FormattingLoggers.getContextLogger();
        }

        @Override
        public boolean isRunning() {
            return true;
        }

        @Override
        public boolean onResampledAudioData(byte[] arg0, int arg1, int arg2) {
            return false;
        }

        @Override
        public boolean onVoiceAmplitudeChanged(double arg0) {
            return false;
        }

        @Override
        public void onVoiceConfigChanged(VoiceConfig arg0, boolean arg1) {

        }
    }

}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Glass 语音命令给定列表中最接近的匹配项 的相关文章

随机推荐