首页 > 解决方案 > 安卓版印地语语音转文本

问题描述

我正在使用以下代码并为印地语发送语言环境,但仍然语音到文本会以英语给出结果。

我希望结果必须是印地语

 /**
     * Showing google speech input dialog
     */
    private void promptSpeechInput() {
        Locale locale;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            locale = (Locale.forLanguageTag("hin"));
        } else {
            locale = (new Locale("hin"));
        }
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, locale);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
                getString(R.string.speech_not_supported));
        try {
            startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
        } catch (ActivityNotFoundException a) {
            Toast.makeText(getApplicationContext(),
                    getString(R.string.otp_send_dynamic_msg),
                    Toast.LENGTH_SHORT).show();
        }
    }

标签: androidgoogle-text-to-speech

解决方案


最后我得到了解决方案,我们必须传递一个 ISO 字符串(如果是印地语它的“hi”)

String languagePref = "hi";
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, languagePref);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, languagePref);
        intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, languagePref);

推荐阅读