Source:
public static void initializeTts(Context context) { mReviewer = new WeakReference<>(context); mTts = new TextToSpeech(context, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { buildAvailableLanguages(); if (availableTtsLocales.size() > 0) { Timber.d("TTS initialized and available languages found"); ((AbstractFlashcardViewer) mReviewer.get()).ttsInitialized(); } else { Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show(); Timber.w("TTS initialized but no available languages found"); } mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String arg0) { if (ReadText.sTextQueue.size() > 0) { String[] text = ReadText.sTextQueue.remove(0); ReadText.speak(text[0], text[1], TextToSpeech.QUEUE_FLUSH); } } @Override @Deprecated public void onError(String utteranceId) { Timber.v("Andoid TTS failed. Check logcat for error. Indicates a problem with Android TTS engine."); new Handler(mReviewer.get().getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(mReviewer.get(), "TTS failed. Check Android settings.", Toast.LENGTH_LONG).show(); } }); } @Override public void onStart(String arg0) { } }); } else { Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show(); Timber.w("TTS not successfully initialized"); } } }); Toast.makeText(context, context.getString(R.string.initializing_tts), Toast.LENGTH_LONG).show(); }

Target:
public static void initializeTts(Context context) { mReviewer = new WeakReference<>(context); mTts = new TextToSpeech(context, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { buildAvailableLanguages(); if (availableTtsLocales.size() > 0) { Timber.d("TTS initialized and available languages found"); ((AbstractFlashcardViewer) mReviewer.get()).ttsInitialized(); } else { Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show(); Timber.w("TTS initialized but no available languages found"); } mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String arg0) { if (ReadText.sTextQueue.size() > 0) { String[] text = ReadText.sTextQueue.remove(0); ReadText.speak(text[0], text[1], TextToSpeech.QUEUE_FLUSH); } } @Override @Deprecated public void onError(String utteranceId) { Timber.v("Andoid TTS failed. Check logcat for error. Indicates a problem with Android TTS engine."); final Uri helpUrl = Uri.parse(mReviewer.get().getString(R.string.link_faq_tts)); final AnkiActivity ankiActivity = (AnkiActivity) mReviewer.get(); ankiActivity.mayOpenUrl(helpUrl); UIUtils.showSnackbar(ankiActivity, R.string.no_tts_available_message, false, R.string.help, v -> ankiActivity.openUrl(helpUrl), ankiActivity.findViewById(R.id.root_layout), new Snackbar.Callback()); } @Override public void onStart(String arg0) { } }); } else { Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show(); Timber.w("TTS not successfully initialized"); } } }); Toast.makeText(context, context.getString(R.string.initializing_tts), Toast.LENGTH_LONG).show(); }