首页 > 解决方案 > 西班牙语 Kotlin 语音识别

问题描述

我想在 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)

谢谢

标签: androidkotlinspeech-to-textvoice-recognition

解决方案


推荐阅读