我想检查是否在用户的设备上下载了特定语言 用于Android TextToSpeech。
我试图这样做:
private void checkVoiceData() {
if (ttsLang == TextToSpeech.LANG_MISSING_DATA
|| ttsLang == TextToSpeech.LANG_NOT_SUPPORTED
|| !(ttsLang == TextToSpeech.LANG_AVAILABLE)) {
Log.e("TTS", "The Language is not supported!");
Toast.makeText(PreviewActivity.this, "Open WI-Fi to Download the Language..", Toast.LENGTH_LONG).show();
}
}
但这没用。我认为这段代码不会检查是否下载了一种语言,是否可以检查该语言?
答案 0 :(得分:0)
因此,我终于找到了一种检查是否已安装语言的方法。这是代码:
private boolean isLanguageInstalled(){
Voice voice = textToSpeech.getVoice();
if(voice != null){
Set<String> features = voice.getFeatures();
//Simplified if statement that returns true if the condition is met
return features != null && !features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED);
}
return false;
}