【发布时间】:2020-05-05 22:26:11
【问题描述】:
我尝试使用 Android Studio 在 Kotlin 中运行语音识别器。 在 stackoverflow 的帮助下解决了我的编译器问题后,我现在面临以下问题:speechRecognizer 不再结束。
我敢肯定,昨天在等待可能是 3 到 5 秒的默认时间后,语音控制结束了。当我什么都没说时,答案是“再试一次”,在其他地方它正确地结束了。
现在“输入语音窗口”在我单击该窗口之前不会结束。 我不知道;我可以改变什么!!!!
我添加了“RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 100”(什么不是建议的!!),但也无济于事
这是语音识别器的代码
fun btnhear(view: View) {
val speechRecognitionIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
speechRecognitionIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault().toString())
speechRecognitionIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 100)
startActivityForResult(speechRecognitionIntent, SPEECHINTENTRQ)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
textView.text = "vor der if loop " + requestCode + " " + resultCode
//var speechresult: String? = String()
if (requestCode == SPEECHINTENTRQ && resultCode == Activity.RESULT_OK) {
textView.text = "in der if loop " + Activity.RESULT_OK
var speechresult2: ArrayList<String> =
data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS) ?: ArrayList()
if (speechresult2.isNullOrEmpty()) {
textView.text = "nothing heard " + Activity.RESULT_OK
}
else {
var spokenText = speechresult2[0]
editText.setText(spokenText)
}
}
else
editText.setText("Keine Eingabe"+requestCode)
//super.onActivityResult(requestCode, resultCode, data)
}
我很感激任何想法,我可能做错了什么。 我在模拟器上运行它并尝试了 2、Pixel 2 API28 和 Pixel API 28
【问题讨论】:
标签: android-studio kotlin speech-recognition duration