5

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

}

andrea.spot.
  • 496
  • 4
  • 9
  • Did you add the user permission tag in your application's manifest? – andrea.rinaldi Dec 10 '13 at 09:54
  • 1
  • 1
    Moreover, is it possible to have a pair of glasses nowadays? Ok forget that. I think the way voice recognition works in GG is a bit different. Refer [here](https://developers.google.com/glass/develop/gdk/input/voice). – Mister Smith Dec 10 '13 at 12:08
  • 1
    @MisterSmith sarcastic? :D thanks for the hint, i've already read that piece of documentation and checked that the described flow works correctly.. i just would like to know if there is the possibility to recognize what the user is saying, without prompting the default-glass-speech-recognizing view – andrea.spot. Dec 10 '13 at 13:18
  • hi there am trying to the something similar and using your code posted above as a starting point, however the service is not getting started even though the startservice() is called can you please point the exact steps to get it working? the service should start recognising the sppech once the user says "ok google" is this possible? – aditya Oct 18 '14 at 08:58

2 Answers2

3

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

Community
  • 1
  • 1
JRomero
  • 4,878
  • 1
  • 27
  • 49
0

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.

Broatian
  • 860
  • 9
  • 10