【问题标题】:Contextual Voice Commands Google Glass上下文语音命令 Google Glass
【发布时间】:2014-12-11 15:07:11
【问题描述】:

我要做的是制作一个应该能够显示“ok, glass”命令以打开上下文语音命令的活动。 我已经实现了它,但只有当我点击活动的触摸板时。是否有可能当我说“好的,玻璃”-> 启动应用程序--> 然后它应该显示我的实时卡,然后出现“好的,玻璃”?

期待您的回答 问候

【问题讨论】:

    标签: google-glass google-gdk


    【解决方案1】:

    这是来自LiveCardDev Guide

    1. 表明您的 MenuActivity 支持上下文语音命令:

      // Initialize your LiveCard as usual.
      mLiveCard.setVoiceActionEnabled(true);
      mLiveCard.publish(LiveCard.PublishMode.REVEAL); // or SILENT
      
    2. 修改您的 MenuActivity 以支持通过语音流调用:

      /**
       * Activity showing the options menu.
       */
      public class MenuActivity extends Activity {
      
          private boolean mFromLiveCardVoice;
          private boolean mIsFinishing;
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              mFromLiveCardVoice =
                      getIntent().getBooleanExtra(LiveCard.EXTRA_FROM_LIVECARD_VOICE, false);
              if (mFromLiveCardVoice) {
                  // When activated by voice from a live card, enable voice commands. The     menu
                  // will automatically "jump" ahead to the items (skipping the guard phrase
                  // that was already said at the live card).
                  getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);
              }
          }
      
          @Override
          public void onAttachedToWindow() {
              super.onAttachedToWindow();
              if (!mFromLiveCardVoice) {
                  openOptionsMenu();
              }
          }
      
          @Override
          public boolean onCreatePanelMenu(int featureId, Menu menu) {
              if (isMyMenu(featureId)) {
                  getMenuInflater().inflate(R.menu.stopwatch, menu);
                  return true;
              }
              return super.onCreatePanelMenu(featureId, menu);
          }
      
          @Override
          public boolean onPreparePanel(int featureId, View view, Menu menu) {
              if (isMyMenu(featureId)) {
                  // Don't reopen menu once we are finishing. This is necessary
                  // since voice menus reopen themselves while in focus.
                  return !mIsFinishing;
              }
              return super.onPreparePanel(featureId, view, menu);
          }
      
          @Override
          public boolean onMenuItemSelected(int featureId, MenuItem item) {
              if (isMyMenu(featureId)) {
                  // Handle item selection.
                  switch (item.getItemId()) {
                      case R.id.stop_this:
                          stopService(new Intent(this, StopwatchService.class));
                          return true;
                  }
              }
              return super.onMenuItemSelected(featureId, item);
          }
      
          @Override
          public void onPanelClosed(int featureId, Menu menu) {
              super.onPanelClosed(featureId, menu);
              if (isMyMenu(featureId)) {
                  // When the menu panel closes, either an item is selected from the menu or the
                  // menu is dismissed by swiping down. Either way, we end the activity.
                  isFinishing = true;
                  finish();
              }
          }
      
          /**
           * Returns {@code true} when the {@code featureId} belongs to the options menu or     voice
           * menu that are controlled by this menu activity.
           */
          private boolean isMyMenu(int featureId) {
              return featureId == Window.FEATURE_OPTIONS_PANEL ||
                     featureId == WindowUtils.FEATURE_VOICE_COMMANDS;
          }
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      相关资源
      最近更新 更多