我正试图让我在Android Studio中开发的Android应用程序上离线工作的文字发表演讲。这是我用来设置语音识别器的代码。
public void openSpeechMode(View view) {
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.getDefault());
if(intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, 10);
} else {
Toast.makeText(context, "Your device does not support Speech Input.", Toast.LENGTH_LONG).show();
}
}
当我在线时,此方法工作正常,但当我离线时,此方法无效。我了解到我需要确保在Android设备上执行以下步骤...,以确保设备具有在离线模式下工作所需的库。
1)Go to Settings
2)Click on “Language and input”
3)Select Google voice typing
4)Select Offline speech recognition
5)Install desired language
6)Once the download was done, turn off the internet and test it !!
我遵循了这些步骤,并且我的Android设备上确实安装了英语(英国)和英语(美国)。但是当我离线时,语音转文本应用仍然无法正常工作。当我单击麦克风时,收到消息“网络未连接”,“重试”。
我做错什么了吗?有人可以协助吗? 谢谢
答案 0 :(得分:0)
您可以尝试设置语言首选项。
String languagePref = "en-US";//as you have downloaded US english model
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, languagePref);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, languagePref);
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, languagePref);