如何在另一个 class 中对 SpeechRecognizer 的结尾做出反应?额外的识别器 class

How to react on the End of a SpeechRecognizer in a other class? Recognizer in extra class

社区,

我在 android 中编程,我有 2 个 classes,主 activity 和另一个 class 带有 SpeechRecognizer(侦听器)。 我想给 activity 一个信号,表明听众已完成列表,我该怎么做? 我是否应该使用 mainActivity-class 扩展 SpeechRecognizer-class,然后从 SpeechRecognizer-class 中的 mainActivity-class 调用方法? 这是我的代码的简化版本,用于理解我的问题:

口渴class:

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

秒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
   }
}

我希望你理解我的问题,我认为它很简单,但我不知道解决方案..

问候

只需在您的 MainActivity 上调用 setRecognitionListener

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) {

        }
    });
    }
}