android - 安卓版印地语语音转文本
问题描述
我正在使用以下代码并为印地语发送语言环境,但仍然语音到文本会以英语给出结果。
我希望结果必须是印地语
/**
* 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();
}
}
解决方案
最后我得到了解决方案,我们必须传递一个 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);
推荐阅读
- javascript - 从数组到对象数组的结构格式
- javascript - Javascript deleteRule() 无法正常运行
- ios - iOS WKWebView 的 didCommitNavigation 从未调用过?
- javascript - 如何根据用户输入创建计数器?
- flutter - 如何在 Flutter 中使用 changeNotifier 与提供者
- javascript - 如果从构造函数(props)中初始化状态,getDerivedStateFromProps 方法如何访问状态?
- reactjs - 当 StepContent 存在于步进器中时,如何将 Material-UI StepConnector 设为点
- c++ - 如何在读取文件时修复 C++ 上的分段错误(核心转储)错误?
- performance - 后端页面复制速度非常慢
- node.js - 使用 Angular 生产后端 Node.js 和 Express 和前端