Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 语音识别器直接给出错误5,然后是错误7。无需等待几秒钟的输入_Android_Speech Recognition_Voice Recognition_Voice_Speech - Fatal编程技术网

Android 语音识别器直接给出错误5,然后是错误7。无需等待几秒钟的输入

Android 语音识别器直接给出错误5,然后是错误7。无需等待几秒钟的输入,android,speech-recognition,voice-recognition,voice,speech,Android,Speech Recognition,Voice Recognition,Voice,Speech,我有以下代码来启动语音识别器: fun startVoiceRecognitionActivityNoUI(value: VOICE_COMMANDS) { Log.i(TAG, "SPEECH Results startVoiceRecognitionActivityNoUI") if (speechRecognizer == null) { speechRecognizer = SpeechRecognizer.createSpeechRecognizer

我有以下代码来启动语音识别器:

  fun startVoiceRecognitionActivityNoUI(value: VOICE_COMMANDS) {
    Log.i(TAG, "SPEECH Results startVoiceRecognitionActivityNoUI")
    if (speechRecognizer == null) {
        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this)
        speechRecognizer?.setRecognitionListener(object : RecognitionListener {
            override fun onReadyForSpeech(params: Bundle?) {
                FL.i(TAG, "SPEECH Results onReadyForSpeech")
                var beep = BeepToneGenerator()
                beep.playTone(this@MainActivity, ToneGenerator.TONE_PROP_BEEP)
            }

            override fun onRmsChanged(rmsdB: Float) {
                if (dialogDialUserCountDown != null) {
                    dialogDialUserCountDown!!.setRMSMarin(30 - 3 * rmsdB)
                }
                if (XelionDialerManager.dialogPhone != null) {
                    XelionDialerManager.dialogPhone!!.setRMSMarin(30 - 3 * rmsdB)
                }
            }

            override fun onBeginningOfSpeech() {
                FL.i(TAG, "SPEECH Results onBeginningOfSpeech")
                if (dialogDialUserCountDown != null) {
                    dialogDialUserCountDown!!.setRMSMarin(30f)
                }
            }

            override fun onEndOfSpeech() {
                FL.i(TAG, "SPEECH Results onEndOfSpeech")
                if (dialogDialUserCountDown != null) {
                    dialogDialUserCountDown!!.setRMSMarin(30f)
                }
            }

            override fun onBufferReceived(buffer: ByteArray?) {}
            override fun onError(error: Int) {
                FL.i(TAG, "SPEECH Results onError: $error")
                willRetryToCall()
            }

            override fun onEvent(eventType: Int, params: Bundle?) {
                FL.i(TAG, "SPEECH Results onEvent")
            }

            override fun onPartialResults(partialResults: Bundle?) {
                Log.i(TAG, "SPEECH Results onPartialResults")
                var data = partialResults?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
                var unstableData = partialResults?.getStringArrayList("android.speech.extra.UNSTABLE_TEXT")
                var matches = ArrayList<String>()
                if (data != null) {
                    data.forEachIndexed { index, element ->
                        matches.add(data.get(index) + unstableData?.get(index))
                    }
                    if (matches != null) {
                        Log.i(TAG, "SPEECH Results onPartialResults are: " + matches.toString())
                    } else Log.i(TAG, "SPEECH Results onPartialResults are NULL")
                    handleVoiceRecogMatches(matches)
                }
                FL.i(TAG, "SPEECH Results onPartialResults")
            }

            override fun onResults(results: Bundle?) {
                var matches = results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
                if (matches != null) {
                    FL.i(TAG, "SPEECH Results are: " + matches.toString())
                } else FL.i(TAG, "SPEECH Results are NULL")
                handleVoiceRecogMatches(matches)
            }
        })
    } else {
        speechRecognizer?.stopListening()
    }
    startListening()
    voiceCommand = value
}

private fun startListening() {
    val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
    speechRecognizer?.startListening(intent)
    object : CountDownTimer(10000, 10000) {
        override fun onTick(millisUntilFinished: Long) {}

        override fun onFinish() {
            speechRecognizer?.stopListening()
        }
    }.start()
}
为什么我会得到onerror5(ERROR_CLIENT),为什么在它开始侦听之后,它会自动得到7(NO_MATCH)
还有可能让它在抛出OneDofspeech之前至少等待4-5秒吗?

我也遇到过同样的问题

使用.cancel()而不是.stopListening()将解决此问题。如果在这之后,它仍然发生。
你可能需要升级谷歌应用程序。

我遇到过同样的问题

使用.cancel()而不是.stopListening()将解决此问题。如果在这之后,它仍然发生。 您可能需要升级谷歌应用程序。

与相同
2019-12-23 16:33:51.604 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onError: 5
2019-12-23 16:33:51.605 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onReadyForSpeech
2019-12-23 16:33:52.358 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onBeginningOfSpeech
2019-12-23 16:33:53.159 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onEndOfSpeech
2019-12-23 16:33:53.317 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onError: 7
2019-12-23 16:33:53.319 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results willRetryToCall TRUE?
2019-12-23 16:33:53.320 19411-19411/com.xelion.android.debug I/Xelion_Android: MainActivity: SPEECH Results startVoiceRecognitionActivityNoUI
2019-12-23 16:33:53.326 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onError: 5
2019-12-23 16:33:53.347 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onReadyForSpeech
2019-12-23 16:33:53.896 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onBeginningOfSpeech
2019-12-23 16:33:54.681 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onEndOfSpeech
2019-12-23 16:33:54.897 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onError: 7
2019-12-23 16:33:54.898 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results willRetryToCall TRUE?
2019-12-23 16:33:54.899 19411-19411/com.xelion.android.debug I/Xelion_Android: MainActivity: SPEECH Results startVoiceRecognitionActivityNoUI
2019-12-23 16:33:54.915 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onError: 5
2019-12-23 16:33:54.932 19411-19411/com.xelion.android.debug I/MainActivity: SPEECH Results onReadyForSpeech