0

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 Answers1

0

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);
E. Fernandes
  • 3,889
  • 4
  • 30
  • 48
  • This will open a Prompt window but how i can achieve same thing without EXTRA_PROMPT message ? do i need to change Mic icon onBeginningOfSpeech and on completion ? – Aryan Singh Jun 21 '15 at 17:56
  • 1
    "_(...) Use the SpeechRecognizer interface. Your app needs to have the RECORD_AUDIO permission, and you can then create a SpeechRecognizer, give it a RecognitionListener and then call its startListening method. You will get callbacks to the listener when the speech recognizer is ready to begin listening for speech and as it receives speech and converts it to text..._" Check out this thread http://stackoverflow.com/a/6317055/2068693 – E. Fernandes Jun 21 '15 at 18:27
  • Sorry if my question is not clear to you. I have no issue in Speech to Text functionality..it's working fine for me..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". – Aryan Singh Jun 21 '15 at 18:46
  • Updated the question to avoid any misunderstanding. – Aryan Singh Jun 21 '15 at 18:53
  • 1
    I believe that with the information of that thread you can implement the controller yourself. Based on its callbacks set the status of the button the way you want. – E. Fernandes Jun 21 '15 at 19:00