【问题标题】:Kotlin speechregognizer does no longer endKotlin 语音识别器不再结束
【发布时间】: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


    【解决方案1】:

    对不起:我的回答是: 我不知道为什么,但偶然我失去了模拟器上的语音识别。 我尝试通过 USB 设备连接在智能手机上运行/调试。

    尝试了几个小时让语音识别在模拟器上再次运行,但不再起作用。检查大量互联网提示,尝试(我认为是所有)设置,安装谷歌助手,无论是否登录我的帐户运行,都没有任何帮助。 很遗憾,但我认为我必须跳过它并直接在智能手机上进行测试(我有 3 部智能手机可以运行“Ok google”,但在模拟器上我失败了......

    【讨论】:

      【解决方案2】:

      并在智能手机上进行测试 - 该应用程序按预期运行

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-23
        • 2011-11-01
        • 1970-01-01
        相关资源
        最近更新 更多