How to use Siri like Mic button in Android Voice Recognition

492 views Asked by At

In my app i am using RecognizerIntent for Android Speech to Text (and Speech to Text functionality is working fine for me) with simple microphone Image button, which will initialize the Speech to Text (below is code snippet)

        btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            sr.startListening(intent);
            // btnSpeak.setClickable(false);
            // promptSpeechInput();
        }
    });

But i just wanted to know how i can use Siri or Skyvi like Microphone button in my App so that it will help end user to determine the current state of Speech to Text engine (Whether it is listening or it stop listening) and i am not using any Prompt window to ask user "Speak Now".

1

There are 1 answers

5
E. Fernandes On

Raise an intent of ACTION_RECOGNIZE_SPEECH type:

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak now");

SearchActivity.this.startActivityForResult(intent, VOICE_RECOGNITION_CODE);