Java Code Examples for android.speech.tts.TextToSpeech#LANG_AVAILABLE
The following examples show how to use
android.speech.tts.TextToSpeech#LANG_AVAILABLE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TtsHandler.java From habpanelviewer with GNU General Public License v3.0 | 6 votes |
private void doHandleCommand(String ttsCmd, String arg, Command cmd) { if (mStatus == TextToSpeech.SUCCESS) { if ("SPEAK".equalsIgnoreCase(ttsCmd)) { mTTS.speak(arg, TextToSpeech.QUEUE_ADD, null); } else { Locale l = new Locale(arg); if (mTTS.isLanguageAvailable(l) >= TextToSpeech.LANG_AVAILABLE) { mTTS.setLanguage(l); } else { cmd.failed("Given locale invalid: " + arg); } } cmd.finished(); } else { cmd.failed("Could not initialize TTS engine!"); } }
Example 2
Source File: AndroidSpeechPlayer.java From graphhopper-navigation-android with MIT License | 5 votes |
private void initializeWithLanguage(Locale language) { boolean isLanguageAvailable = textToSpeech.isLanguageAvailable(language) == TextToSpeech.LANG_AVAILABLE; if (!isLanguageAvailable) { Timber.w("The specified language is not supported by TTS"); return; } languageSupported = true; textToSpeech.setLanguage(language); }
Example 3
Source File: MainService.java From android-play-games-in-motion with Apache License 2.0 | 4 votes |
@Override public void onCreate() { // The service is being created. Utils.logDebug(TAG, "onCreate"); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(CHOICE_NOTIFICATION_ACTION_1); intentFilter.addAction(CHOICE_NOTIFICATION_ACTION_2); intentFilter.addAction(CHOICE_NOTIFICATION_ACTION_3); registerReceiver(mReceiver, intentFilter); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // Determines the behavior for handling Audio Focus surrender. mAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() { @Override public void onAudioFocusChange(int focusChange) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS) { if (mTextToSpeech.isSpeaking()) { mTextToSpeech.setOnUtteranceProgressListener(null); mTextToSpeech.stop(); } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } // Abandon Audio Focus, if it's requested elsewhere. mAudioManager.abandonAudioFocus(mAudioFocusChangeListener); // Restart the current moment if AudioFocus was lost. Since AudioFocus is only // requested away from this application if this application was using it, // only Moments that play sound will restart in this way. if (mMission != null) { mMission.restartMoment(); } } } }; // Asynchronously prepares the TextToSpeech. mTextToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { // Check if language is available. switch (mTextToSpeech.isLanguageAvailable(DEFAULT_TEXT_TO_SPEECH_LOCALE)) { case TextToSpeech.LANG_AVAILABLE: case TextToSpeech.LANG_COUNTRY_AVAILABLE: case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE: Utils.logDebug(TAG, "TTS locale supported."); mTextToSpeech.setLanguage(DEFAULT_TEXT_TO_SPEECH_LOCALE); mIsTextToSpeechReady = true; break; case TextToSpeech.LANG_MISSING_DATA: Utils.logDebug(TAG, "TTS missing data, ask for install."); Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); break; default: Utils.logDebug(TAG, "TTS local not supported."); break; } } } }); mMediaPlayer = new MediaPlayer(); }
Example 4
Source File: FailoverTextToSpeech.java From talkback with Apache License 2.0 | 2 votes |
/** * Returns {@code true} if the specified status indicates that the language is available. * * @param status A language availability code, as returned from {@link * TextToSpeech#isLanguageAvailable}. * @return {@code true} if the status indicates that the language is available. */ private static boolean isNotAvailableStatus(int status) { return (status != TextToSpeech.LANG_AVAILABLE) && (status != TextToSpeech.LANG_COUNTRY_AVAILABLE) && (status != TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE); }