/** * Returns true if the TTS engine supports the language of the locale represented by localeCode * (which should be in the format returned by Locale.toString()), false otherwise. */ private static boolean isLanguageAvailable(String localeCode) { return mTts.isLanguageAvailable(localeFromStringIgnoringScriptAndExtensions(localeCode)) >= TextToSpeech.LANG_AVAILABLE; }
public static void buildAvailableLanguages() { availableTtsLocales.clear(); Locale[] systemLocales = Locale.getAvailableLocales(); for (Locale loc : systemLocales) { try { int retCode = mTts.isLanguageAvailable(loc); if (retCode >= TextToSpeech.LANG_COUNTRY_AVAILABLE) { availableTtsLocales.add(loc); } else { Timber.v("ReadText.buildAvailableLanguages() :: %s not available (error code %d)", loc.getDisplayName(), retCode); } } catch (IllegalArgumentException e) { Timber.e("Error checking if language " + loc.getDisplayName() + " available"); } } }
public class TtsProviderImpl extends TtsProviderFactory implements TextToSpeech.OnInitListener { private TextToSpeech tts; public void init(Context context) { if (tts == null) { tts = new TextToSpeech(context, this); } } @Override public void say(String sayThis) { tts.speak(sayThis, TextToSpeech.QUEUE_FLUSH, null); } @Override public void onInit(int status) { Locale loc = new Locale("de", "", ""); if (tts.isLanguageAvailable(loc) >= TextToSpeech.LANG_AVAILABLE) { tts.setLanguage(loc); } } public void shutdown() { tts.shutdown(); }}
public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { ttsIsInit = true; if (tts.isLanguageAvailable(Locale.UK) >= 0) tts.setLanguage(Locale.UK); tts.setPitch(0.8f); tts.setSpeechRate(1.1f); speak(); } } });
private TextToSpeech myTTS; // Define the TTS objecy private int MY_DATA_CHECK_CODE = 0; //write the following code in oncreate method or whereever you want to use this { myTTS = new TextToSpeech(this, this); Intent checkTTSIntent = new Intent(); checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE); speakWords("Pass the String here"); } private void speakWords(String speech) { //speak straight away //myTTS.setLanguage(Locale.US); System.out.println(speech + " TTSTTTS"); myTTS.speak(speech, TextToSpeech.LANG_COUNTRY_AVAILABLE, null); } public void onInit(int status) { // TODO Auto-generated method stub if (status == TextToSpeech.SUCCESS) { if(myTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE) myTTS.setLanguage(Locale.US); } else if (status == TextToSpeech.ERROR) { Toast.makeText(getApplicationContext(), "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show(); } }
if(myTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE) myTTS.setLanguage(Locale.US);
if (!locales[i].getVariant().isEmpty()) continue; try { if (mTextToSpeech.isLanguageAvailable(locales[i]) > 0) { String name = locales[i].getDisplayLanguage(); if (!locales[i].getCountry().isEmpty()) {
if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE) myTTS.setLanguage(Locale.US); } else if (initStatus == TextToSpeech.ERROR) {
if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE) myTTS.setLanguage(Locale.US); } else if (initStatus == TextToSpeech.ERROR) {
public void onInit(int status) { if(status==TextToSpeech.SUCCESS){ if(textToSpeech.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE){ textToSpeech.setLanguage(Locale.US);
if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE) myTTS.setLanguage(Locale.US); } else if (initStatus == TextToSpeech.ERROR) {
if (m_tts.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE) { m_tts.setLanguage(Locale.US); Toast.makeText(this, "Text To Speech ", Toast.LENGTH_LONG)
int result; if (locale == null || (result = tts.isLanguageAvailable(locale)) == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.d(TAG_ASKQ, "TextToSpeech: language not supported: " +