我正在尝试使RecognizerIntent尊重一种自定义语言,并将其设置为收听,但是这是行不通的。看起来它只是不使用我要发送的参数,仅考虑了系统设置(如果我更改系统的“语音搜索”设置,则可以使用)。

这就是我创建Intent的方式:

val spanish = Locale("es", "ES").toString()
val recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)

recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true)
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, spanish)
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, spanish)
recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, spanish)
recognizerIntent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", arrayOf(spanish))

startActivityForResult(recognizerIntent, REQUEST_SPEECH)


任何帮助将非常感激

最佳答案

 if (sharedPreferences.getAppLanguage() == LANGUAGE_ENGLISH) {
            recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
        } else {
            recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ar-AE")
        }

关于android - 识别器 Intent 不尊重语言,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53594168/

10-10 18:03