识别器意图不尊重语言

时间:2018-12-03 12:46:58

标签: android android-tv

我正在尝试让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)

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

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