Glass voice command nearest match from given list

前端 未结 3 990
一向
一向 2020-11-27 17:25

With Glass you can launch an app via the \'OK, Glass\' menu and it seems to pick the nearest match unless a command is miles off, and you can obviously see the list of comma

3条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 17:46

    The Google GDK doesn't support this feature yet. However, the necessary features are already available in some libraries and you can use them as long as the GDK doesn't support this natively. What you have to do:

    1. Pull the GlassVoice.apk from your Glass: adb pull /system/app/GlassVoice.apk

    2. Use dex2jar to convert this apk into a jar file.

    3. Add the jar file to your build path

    Now you can use this library like this:

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

提交回复
热议问题