diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixTextToSpeech.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixTextToSpeech.java index 9c39ccd48..0928ee237 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixTextToSpeech.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixTextToSpeech.java @@ -34,11 +34,13 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import org.kiwix.kiwixmobile.core.CoreApp; import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.utils.LanguageUtils; import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer; +import org.kiwix.kiwixmobile.core.extensions.ContextExtensionsKt; import static org.kiwix.kiwixmobile.core.utils.Constants.TAG_KIWIX; @@ -133,6 +135,12 @@ public class KiwixTextToSpeech { } else { tts.setLanguage(locale); + if (getFeatures(tts, locale).contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED)) { + ContextExtensionsKt.toast(context, R.string.tts_lang_not_supported, + Toast.LENGTH_LONG); + return; + } + if (requestAudioFocus()) { loadURL(webView); } @@ -140,6 +148,12 @@ public class KiwixTextToSpeech { } } + @SuppressLint("NewApi") + private Set getFeatures(TextToSpeech tts, Locale locale) { + return VERSION.SDK_INT < VERSION_CODES.LOLLIPOP ? tts.getFeatures(locale) + : tts.getVoice().getFeatures(); + } + private void loadURL(WebView webView) { // We use JavaScript to get the content of the page conveniently, earlier making some // changes in the page