@SuppressWarnings("deprecation") // Movement to new API tracked in github as #5021 public static void speak(String text, String loc, int queueMode) { int result = mTts.setLanguage(localeFromStringIgnoringScriptAndExtensions(loc)); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message) +" ("+loc+")", Toast.LENGTH_LONG).show(); Timber.e("Error loading locale " + loc); } else { if (mTts.isSpeaking() && queueMode == TextToSpeech.QUEUE_FLUSH) { Timber.d("tts engine appears to be busy... clearing queue"); stopTts(); //sTextQueue.add(new String[] { text, loc }); } Timber.d("tts text '%s' to be played for locale (%s)",text, loc); mTts.speak(mTextToSpeak, queueMode, mTtsParams); } }
public void stop() { if (mTextToSpeech != null) { if (mTextToSpeech.isSpeaking()) { mTextToSpeech.stop(); } mTextToSpeech.shutdown(); } if (mediaPlayer != null && mediaPlayer.isPlaying()) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer = null; mediaHandler.removeCallbacks(mHighlightTask); } } }
public void stateChanged(MediaOverlayPlayPauseEvent event) { if (event.isStateChanged()) { if (mediaPlayer != null) { mediaPlayer.pause(); } if (mTextToSpeech != null && mTextToSpeech.isSpeaking()) { mTextToSpeech.stop(); } } else { if (event.isPlay()) { UiUtil.keepScreenAwake(true, context); } else { UiUtil.keepScreenAwake(false, context); } if (mediaType == MediaType.SMIL) { playSMIL(); } else { if (mTextToSpeech.isSpeaking()) { mTextToSpeech.stop(); mIsSpeaking = false; callbacks.resetCurrentIndex(); } else { mIsSpeaking = true; callbacks.highLightTTS(); } } } }
public static boolean isSpeaking() { return speaker.isSpeaking(); } public static void speak(String speech) {
public void pause() { isPaused = true; Log.d(TAG, "TTS Paused at " + currentQueueIndex); if (tts != null && tts.isSpeaking()) { tts.stop(); } }
public void stop() { if (queue != null) { queue.clear(); } currentQueueIndex = 0; isPaused = false; if (tts != null && tts.isSpeaking()) { tts.stop(); } }
public void mute() { muted = true; if (textToSpeech.isSpeaking()) { textToSpeech.stop(); } }
import android.speech.tts.TextToSpeech; import java.util.Locale; public class Test implements TextToSpeech.OnInitListener { TextToSpeech tts; String text; public Test(String text) { tts = new TextToSpeech(MyApplication.getContext(), this); this.text = text; } @Override public void onInit(int i) { if (i == TextToSpeech.SUCCESS) { tts.setLanguage(Locale.GERMAN); tts.setPitch(3); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); while(tts.isSpeaking()); } } }
/** * Speak the given text * @param text */ public void speak(String text) { if( ready ) { if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { tts.speak(text, TextToSpeech.QUEUE_ADD, null, null); } else { tts.speak(text, TextToSpeech.QUEUE_ADD, null); } while(tts.isSpeaking()) { //wait } //stop service stopSelf(); } }
@Test public void shouldStopOnMute() { speakerbox.unmute(); speakerbox.play("Hello"); speakerbox.mute(); assertThat(speakerbox.getTextToSpeech().isSpeaking()).isFalse(); }
if (tts.isSpeaking()) { if (tts.stop() == TextToSpeech.SUCCESS) { onSpeakingListener.onSpeakingEnded();