Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

android - How to Navigate a Google Glass GDK Immersion Application using Voice Command only?

How would I go about coding a voice trigger to navigate Google Glass Cards?

This is how I see it happening:

1) "Ok Glass, Start My Program"

2) Application begins and shows the first card

3) User can say "Next Card" to move to the next card 
(somewhat the equivalent of swiping forward when in the timeline)

4) User can say "Previous Card" to go back 

The cards that I need to display are simple text and images, I'm wondering if I can setup a listener of some type to listen for voice commands while the card is being shown.


I've researched Glass voice command nearest match from given list but wasn't able to run the code, although I do have all the libraries.

side note: It's important that the user still see the card when using the voice command. Also his hands are busy so tap/swipe isn't an option.

Any ideas on how to control the timeline within my Immersion app using only voice control? would be greatly appreciated!

I am tracking https://code.google.com/p/google-glass-api/issues/detail?id=273 as well.


My ongoing research made me look back at Google Glass Developer to use Google's suggested way of listening to gestures: https://developers.google.com/glass/develop/gdk/input/touch#detecting_gestures_with_a_gesture_detector

How can we activate these gestures with voice commands?


Android just beta-released wearable devices upgrade for android http://developer.android.com/wear/notifications/remote-input.html, Is there a way we can use this to answer my question? it still feels like we are still 1-step away since we can call on the service but not have it "sleep" and "wake up" as a background service when we talk.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

this thing define in onCreate method

mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 
    //  mAudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);

    sr = SpeechRecognizer.createSpeechRecognizer(context);       
    sr.setRecognitionListener(new listener(context));   

    //      intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
    intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,context.getPackageName());
    sr.startListening(intent);
    Log.i("111111","11111111"+"in");

This listener class simply add in your class

class  listener implements RecognitionListener          
{
    Context context1;
    public listener(Context context)
    {
        //Log.i("onError startListening","enter"+"nam");
        context1=context;
    }
    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");
        sr.startListening(intent);
    }
    public void onError(int error)
    {
        //Log.d(TAG,  "error " +  error);
        //7 -No recognition result matched.
        //9 - vInsufficient permissions 
        //6 - No speech input 
        //8 RecognitionService busy. 
        //5 Other client side errors. 
        //3 Audio recording error.  
        //  mText.setText("error " + error);

        if(error==6 || error==7 || error==4  || error==1 || error==2 || error==5 || error==3 || error==8 || error==9 )
        { 
            sr.startListening(intent);
            //Log.i("onError startListening","onError startListening"+error);
        }
    }
    public void onResults(Bundle results)                   
    {
        //Log.v(TAG,"onResults" + results);
        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);

        //Toast.makeText(context1, "results: "+data.get(0).toString(), Toast.LENGTH_LONG).show();
        //Log.v("my", "output"+"results: "+data.get(0).toString());

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...