Is it possible to have Android Voice Recognition (as a custom service) on Google Glass?

一世执手 提交于 2019-12-18 13:37:52

问题


We have a demo android application (Android 4.0.3) that runs voice recognition as a service, and (continuosly) logs the results of the recognition on the view.

Everything is working fine in our smartphones.

We would like to replicate this scenario in a Google Glass immersion application, but we always have this error message when we try to start the service:

no selected voice recognition service

Are there some known limitations? Or have someone figured out how to resolve this kind of problem?

Thanks in advance

This is some significant code of the activity:

public class MainActivity extends Activity implements Observer {
   ...
   @Override
   protected void onStart() {
      super.onStart();
      //Toast.makeText(this, "Hi guys", Toast.LENGTH_LONG);
      startService(new Intent(this, SilentVoiceRecognitionService.class));
   }
   ...
}

And this is the code of the service:

public class SilentVoiceRecognitionService extends Service {
   protected AudioManager mAudioManager; 
   protected SpeechRecognizer mSpeechRecognizer;
   protected Intent mSpeechRecognizerIntent;
   protected final Messenger mServerMessenger = new Messenger(new IncomingHandler(this));

   private Model model = Model.getInstance();

   static final String TAG = "SilentRecognizer";
   static final int MSG_RECOGNIZER_START_LISTENING = 1;
   static final int MSG_RECOGNIZER_CANCEL = 2;

   protected boolean mIsListening;

   @Override
   public void onCreate()
   {
       super.onCreate();
       mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
       mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
       mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
       mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                                     RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
       mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                                     this.getPackageName());
   }

   @Override
   public int onStartCommand(Intent intent, int flags, int startId) {
       Log.i("LocalService", "Received start id " + startId + ": " + intent);
       // We want this service to continue running until it is explicitly
       // stopped, so return sticky.

       mSpeechRecognizer.startListening(mSpeechRecognizerIntent);

       return START_STICKY;
   }

   @Override
   public void onDestroy()
   {
       super.onDestroy();

       if (mSpeechRecognizer != null)
       {
           mSpeechRecognizer.destroy();
       }
   }

   protected class SpeechRecognitionListener implements RecognitionListener
   {

       ...
   }


   protected static class IncomingHandler extends Handler
   {
       private WeakReference<SilentVoiceRecognitionService> mtarget;

       IncomingHandler(SilentVoiceRecognitionService target)
       {
           mtarget = new WeakReference<SilentVoiceRecognitionService>(target);
       }


       @Override
       public void handleMessage(Message msg)
       {
           final SilentVoiceRecognitionService target = mtarget.get();

           switch (msg.what)
           {
               case MSG_RECOGNIZER_START_LISTENING:

                    if (!target.mIsListening)
                    {
                   target.mSpeechRecognizer.startListening(target.mSpeechRecognizerIntent);
                        target.mIsListening = true;
                       //Log.d(TAG, "message start listening"); //$NON-NLS-1$
                    }
                    break;

                case MSG_RECOGNIZER_CANCEL:
                     target.mSpeechRecognizer.cancel();
                     target.mIsListening = false;
                     //Log.d(TAG, "message canceled recognizer"); //$NON-NLS-1$
                     break;
            }
      } 
   }

}


回答1:


This feature has been recently accepted but not yet available, see https://code.google.com/p/google-glass-api/issues/detail?id=245

You can load the additional mentioned apk to get the functionality for the mean time. See Using Android Speech Recognition APIs from Google Glass




回答2:


As of XE16 it is now possible to use the SpeechRecognizer directly and get the results through the SpeechRecognitionListener.

Unfortunately this still dosen't work offline.



来源:https://stackoverflow.com/questions/20490921/is-it-possible-to-have-android-voice-recognition-as-a-custom-service-on-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!