Using google speech recognition for use on Android hardware without displaying specific ui

This is my first question here on stackoverflow, so sorry if I'm doing something wrong. I have a wear app for android where the user has to select an item from a list.

I want the user to be able to select an item via voice commands. I was able to do this as suggested in the google documentation , but I have to implement a button to start speech recognition and it will show up as full screen.

I want the user to be able to see the list while speech recognition is active. Is there any solution for this?

EDIT: I may have found the solution I was looking for. It is a speech recognizer that seems to be able to do what I want. I'll have to delve into this and update this post if this is a solution.

+3


source to share


1 answer


Have you found a solution yet? I used the SpeechRecognizer class, which should be in the main thread with a recognition listener injected, or you can have an inner class that implements the same.

SpeechListenerClass speechListenerObj;
SpeechRecognizer speechRecognizerObj;
Intent speechRecognizerIntentObj;



protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    speechListenerObj = new SpeechListenerClass(getApplicationContext(),this);
    speechRecognizerObj = SpeechRecognizer.createSpeechRecognizer(this);
    speechRecognizerIntentObj = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
    speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en");
               `   ```````````             speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.                        LANGUAGE_MO  DEL_WEB_SEARCH);
    speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
    speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,this.getPackageName());

    speechRecognizerObj.startListening(speechRecognizerIntentObj);
    speechRecognizerObj.setRecognitionListener(new Listener());

      

}



class Listener implements  RecognitionListener
    {


        @Override
        public void onReadyForSpeech(Bundle params) {

        }

        @Override
        public void onBeginningOfSpeech() {

        }

        @Override
        public void onRmsChanged(float rmsdB) {

        }

        @Override
        public void onBufferReceived(byte[] buffer) {

        }

        @Override
        public void onEndOfSpeech() {

        }

        @Override
        public void onError(int error) {

        }

        @Override
        public void onResults(Bundle results) {

        }

        @Override
        public void onPartialResults(Bundle partialResults) {

        }

        @Override
        public void onEvent(int eventType, Bundle params) {

        }
    }

      

This works for me, but the problem is that it opens the google search dialog on an Android Wear device (Moto 360). The same code acts as a background task when working on the phone. Please let me know if any changes are made.

0


source







All Articles