0

community,

I'm programming in android and i have 2 classes, the mainactivity and a other class with a SpeechRecognizer(a listener). I want to give the activity a sign that the listener is done with listining, how can i do that? Should i extend the SpeechRecognizer-class with the mainActivity-class and then call a method from the mainActivity-class in the SpeechRecognizer-class? Here is a simplified version of my code to understand my problem:

thirst class:

puplic class mainActivity{
  onCreate(){
  speech.startListening();
}
}

second class:

pulbic class speech implements Recognizer{

   startListening(){
   //start the listener
   }

   @Override
   onResult(){
   //hear i get my string after a random various amount of time
   //(when the recognizer is done with hearing my stuff)
   //at this point i want to let the other class know, that im done here
   }
}

I hope you understand my problem, i think its an easy one, but i dont know a solution..

Greetings

Phil
  • 304
  • 1
  • 5
  • 12
  • Possible duplicate of [Google SpeechRecognizer and pocketsphinx in two different classes, how to loop them?](http://stackoverflow.com/questions/36403686/google-speechrecognizer-and-pocketsphinx-in-two-different-classes-how-to-loop-t) – Nikolay Shmyrev Apr 05 '16 at 12:08

1 Answers1

1

Just call setRecognitionListener on your MainActivity.

public class MainActivity extends Activity {

    SpeechRecognizer speech;

    public void onCreate(){
        super.onCreate();
        speech.startListening();
        recognizer.setRecognitionListener(new RecognitionListener() {
        @Override
        public void onReadyForSpeech(Bundle bundle) {

        }

        @Override
        public void onBeginningOfSpeech() {

        }

        @Override
        public void onRmsChanged(float v) {

        }

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

        }

        @Override
        public void onEndOfSpeech() {

        }

        @Override
        public void onError(int i) {

        }

        @Override
        public void onResults(Bundle bundle) {

        }

        @Override
        public void onPartialResults(Bundle bundle) {

        }

        @Override
        public void onEvent(int i, Bundle bundle) {

        }
    });
    }
}
Emin Ayar
  • 1,104
  • 9
  • 13
  • I think that this will not work or rather, i dont know how to use this. My question was to simplified, here is the longer one http://stackoverflow.com/questions/36403686/google-speechrecognizer-and-pocketsphinx-in-two-different-classes-how-to-loop-t – Phil Apr 04 '16 at 13:14
  • Just think you have a button to start listening speech. After clicked this button you will use `startListening()` function. And when your speech end, `onEndOfSpeech()` function will be fired – Emin Ayar Apr 04 '16 at 13:17
  • Mhh i dont understand what do you try to say me. From where comes the recognizer? (i set my setRecognitionListener in the other class, not in the MainActivity, look at my other question) – Phil Apr 04 '16 at 13:22