如何检查是否为 TTS 下载语言

How to check whether a language is downloaded or not for TTS

我想检查特定语言 是否已下载 或未在用户设备上用于 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();
        }
    }

但这没有用。我认为这段代码不会检查是否下载了语言,有没有办法检查?

所以,我终于找到了一种方法来检查是否安装了一种语言。这是代码:

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;
    }