您好我正在构建一个使用语音识别的应用程序,我的意图是,用户可以在没有互联网的情况下使用该应用程序,因此他需要在智能手机中下载语言包。
1 - 是否可以检查手机中是否已有手机包?
2 - 我可以向用户显示语音包系统配置(如wifi或gps配置)吗?
答案 0 :(得分:1)
检查已安装的TTS。使用您活动中的此代码
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
checkTTSIntent.putExtra(
TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR,
Locale.getDefault());
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
在onActivityResult中添加此代码,用于检查tts引擎是否可用
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL) {
//TTS is not installed for the default language
}
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
Toast.makeText(
getApplicationContext(),
"TTS Engine Data for default language is installed ",
Toast.LENGTH_LONG).show();
} else {
//TTS for default language not installed.check for other languages
if (data != null) {
ArrayList<String> availableLanguages = data
.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
if (availableLanguages.isEmpty()) {
// no language data available, prompt for install
showDialog();
} else {
// some language data is available, create TTS instance
Toast.makeText(
getApplicationContext(),
"TTS Engine Data for default language is installed.",
Toast.LENGTH_LONG).show();
}
}
}