3

I have a program here, This is a function that is called on a click of a button. I would like the speech recognition to keep recognizing speech until stoplistening() is called. I keep getting the error codes 6, 7 and every time I speak it stops listening after a few seconds of silence, I even defined the silence and input values:

 listenerintent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS , 200000)
            listenerintent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS , 5000000)

but the application still closes after 2 seconds of silence if something is said before the silence. If nothing is said then the speech-recognition listens for the maximum amount of time I defined above.

I would like to have the speech recognition to be active regardless of the silence after something is recognized. Any parameter I am missing that could solve this issue? or is this library incapable of going forever and must stop after something is recognized? Is there another end pointer I am overlooking?

 var recogobj = SpeechRecognizer.createSpeechRecognizer(this)
        var listenerintent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        listenerintent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS , 200000)
        listenerintent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS , 5000000)
        listenerintent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 5000000)



        val recoglistener = object : RecognitionListener {
            override fun onReadyForSpeech(params: Bundle?) {

            }

            override fun onRmsChanged(rmsdB: Float) {


            }

            override fun onBufferReceived(buffer: ByteArray?) {

            }

            override fun onPartialResults(partialResults: Bundle?) {
                    Toast.makeText(this@Recordinit , RecognizerIntent.EXTRA_PARTIAL_RESULTS , Toast.LENGTH_LONG).show()
                var data = partialResults!!.getStringArray(RecognizerIntent.EXTRA_PARTIAL_RESULTS)
                for (result in data.orEmpty()){


                if (result == "test") {
                    recogobj.stopListening()
                    Toast.makeText(this@Recordinit, "ok ", Toast.LENGTH_SHORT).show()
                }
                }
            }

            override fun onEvent(eventType: Int, params: Bundle?) {

            }

            override fun onBeginningOfSpeech() {


            }

            override fun onEndOfSpeech() {



            }

            override fun onError(error: Int) {
                if (error ==6 || error == 7){
                    recogobj.startListening(listenerintent)
                }
                else{
                    Toast.makeText(this@Recordinit ,"${error}" , Toast.LENGTH_LONG).show()
                }





            }

            override fun onResults(results: Bundle?) {




            }

        }
        recogobj.setRecognitionListener(recoglistener)

            recogobj.startListening(listenerintent)

    }
RonRon Scores
  • 163
  • 2
  • 11
  • 2
    Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should **only** be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See [when is it appropriate to remove an IDE tag](https://meta.stackoverflow.com/a/315196/6296561), [How do I avoid misusing tags?](https://meta.stackoverflow.com/q/354427/6296561), and [the tagging guide](/help/tagging). Use [android] or other relevant tags instead. – Zoe Jun 01 '20 at 09:20
  • Does this answer your question? [Continuous Speech Recognition Android](https://stackoverflow.com/questions/3148603/continuous-speech-recognition-android) – Nikolay Shmyrev Jun 02 '20 at 22:43
  • I am getting that there is no way to implement continuous speech recognition with this library? – RonRon Scores Jun 03 '20 at 05:20
  • @RonRonScores Have you even been able to find a way to implement continuous speech recognition? – WebViewer Nov 29 '22 at 15:27

0 Answers0