Speech only first time

北城余情 提交于 2019-12-13 09:20:48

问题


I am interested in speech recognition in Android but I can't do it: it is not continuous. If you stop speaking, it doesn't continue, and you have to click on the button again.

I do not want this behaviour..

Does anybody have any suggestions as to what I can to fix this?

Recognise speech only first time I do not want this behaviour.

Here is the code:

    private SpeechRecognizer speech;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    speech = SpeechRecognizer.createSpeechRecognizer(this);
    speech.setRecognitionListener(this);

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
    this.getPackageName());

    speech.startListening(intent);
    }

     @Override
     public void onBeginningOfSpeech()
     {
     }

        @Override
        public void onBufferReceived(byte[] arg0)
         {
        }

        @Override
        public void onEndOfSpeech()
          {
            }

         @Override
        public void onError(int e)
           {
          }

      @Override
      public void onEvent(int arg0, Bundle arg1)
      {
         }

      @Override
       public void onPartialResults(Bundle arg0)
       {
         }


          public void onReadyForSpeech(Bundle arg0)
         {
           }

         @Override
         public void onResults(Bundle data)
         {
           ArrayList<String> matches = data.getStringArrayList(
           SpeechRecognizer.RESULTS_RECOGNITION);


           }

           @Override
            public void onRmsChanged(float arg0)
             {
           }  

回答1:


Try to call again

speech.startListening(intent);

inside On Results and OnError.



来源:https://stackoverflow.com/questions/32531721/speech-only-first-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!