Merge pull request #1764 from mohamedsamehkhalil/issue/1510

Add voice data checks for Read Aloud
This commit is contained in:
Seán Mac Gillicuddy 2020-02-21 09:19:38 +00:00 committed by GitHub
commit 780ddd5e94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<String> 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