Browse Source

getTtsLanguage: workaround NPE in >= Lollipop.

When there is no TTS engine selected, mTts.getVoice() will throw
a NullPointerException. This is a workaround to cope with this bug
in Android.
master
Reece H. Dunn 10 years ago
parent
commit
135f852598
1 changed files with 8 additions and 1 deletions
  1. 8
    1
      android/src/com/reecedunn/espeak/eSpeakActivity.java

+ 8
- 1
android/src/com/reecedunn/espeak/eSpeakActivity.java View File

private Locale getTtsLanguage() { private Locale getTtsLanguage() {
if (mTts != null) { if (mTts != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
android.speech.tts.Voice voice = mTts.getVoice();
android.speech.tts.Voice voice = null;
try {
voice = mTts.getVoice();
} catch (NullPointerException e) {
// Android Lollipop and later may throw a NullPointerException
// if a voice is not selected.
return null;
}
if (voice != null) { if (voice != null) {
return voice.getLocale(); return voice.getLocale();
} }

Loading…
Cancel
Save