Code example for TextToSpeech

Methods: isLanguageAvailable, setLanguage

0
			  mTts.shutdown();
	} 
 
	private void setCurrentTTSLocale() { 
		locale = getLanguageAsBCP47();
		if(mTts.isLanguageAvailable(locale) == TextToSpeech.LANG_COUNTRY_AVAILABLE)
			mTts.setLanguage(locale);
		else 
			mTts.setLanguage(Locale.getDefault());
	} 
 
	private void speak(String text, String utteranceID) {
		setCurrentTTSLocale(); 
		HashMap<String, String> ttsParams = new HashMap<String, String>();
		ttsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceID);
		mTts.speak(text, TextToSpeech.QUEUE_FLUSH,
				ttsParams);
	} 
 
	/** 
	 * Implements OnUtteranceCompletedListener Interface.