西班牙语中的 Kotlin 语音识别

时间:2020-12-21 01:24:55

标签: android kotlin speech-to-text voice-recognition

我想在 Kotlin 中制作一个语音识别应用程序。当我设置“en-US”语言时,一切正常,但是当我设置“es-ES”时,语音识别永远不会结束。 onPartialResults 在我说话时给我一些结果,但 onResults 永远不会被调用,识别永远不会结束。仅当我设置“es-ES”时。如果我设置“en-US”,则调用 onResults 并完美识别。 我已经下载了 en-US 语言和 es-ES 语言,以便在我的配置中进行离线识别。

发生了什么?我需要帮助

我的代码:

val language = "es-ES" //"en-US"
val speech: SpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(activity)
speech.setRecognitionListener(this)
intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language)
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, language)
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true)
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 2)
speech.startListening(intent)

谢谢

0 个答案:

没有答案