4

I recently updated Google glass to the latest XE17 version. In order to do a voice recognition using Google, we use the following Intent.

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    startActivityForResult(intent, SPEECH_REQUEST);

However, this opens up the voice recognition activity with the default microphone icon. I want to avoid this and instead run the speech recognition feature as a background service in Glass.

I know how to do this in Android (mobile). However when I tried doing the same in Glass it did not work.

My code is as follows:

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); 
    sr.startListening(intent);

    class listener implements RecognitionListener          
 {
    public void onReadyForSpeech(Bundle params)
    {
        Log.d(TAG, "onReadyForSpeech");
    }
    public void onBeginningOfSpeech()
    {
        Log.d(TAG, "onBeginningOfSpeech");
    }
    public void onRmsChanged(float rmsdB)
    {
        Log.d(TAG, "onRmsChanged");
    }
    public void onBufferReceived(byte[] buffer)
    {
        Log.d(TAG, "onBufferReceived");
    }
    public void onEndOfSpeech()
    {
        Log.d(TAG, "onEndofSpeech");
    }
    public void onError(int error)
    {
        Log.d(TAG,  "error " +  error);

    }
    public void onResults(Bundle results)                   
    {
        String str = new String();
        Log.d(TAG, "onResults " + results);
        @SuppressWarnings("rawtypes")
        ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
        for (int i = 0; i < data.size(); i++){
            Log.d(TAG, "result " + data.get(i));
            str += data.get(i);

        }

    }
    public void onPartialResults(Bundle partialResults)
    {
        Log.d(TAG, "onPartialResults");
    }
    public void onEvent(int eventType, Bundle params)
    {
        Log.d(TAG, "onEvent " + eventType);
    }
      }

Can someone help me out in this?

Parth Doshi
  • 4,200
  • 15
  • 79
  • 129
  • I have the same issue on XE17. Can you post your logs here? –  May 13 '14 at 15:34
  • There is a know issue with XE17 and speech [see here](https://code.google.com/p/google-glass-api/issues/detail?id=511&q=component%3DGDK&colspec=ID%20Type%20Status%20Priority%20Owner%20Component%20Summary) and [here](http://stackoverflow.com/questions/23558412/speechrecognizer-broken-after-google-glass-xe17-update-how-to-work-around) – Ben May 14 '14 at 16:03
  • @Mighter: I will post the logs soon. My glass is not working! I got the white screen of death – Parth Doshi May 14 '14 at 16:44

1 Answers1

2

Get the package as follows:

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());

Also make sure you have the following permissions set:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET"/>
Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63