Example usage for android.speech.tts TextToSpeech LANG_COUNTRY_VAR_AVAILABLE

List of usage examples for android.speech.tts TextToSpeech LANG_COUNTRY_VAR_AVAILABLE

Introduction

In this page you can find the example usage for android.speech.tts TextToSpeech LANG_COUNTRY_VAR_AVAILABLE.

Prototype

int LANG_COUNTRY_VAR_AVAILABLE

To view the source code for android.speech.tts TextToSpeech LANG_COUNTRY_VAR_AVAILABLE.

Click Source Link

Document

Denotes the language is available exactly as specified by the locale.

Usage

From source file:Main.java

private static boolean isSetLanguageOk(int setLanguageReturnCode) {
    switch (setLanguageReturnCode) {
    case TextToSpeech.LANG_AVAILABLE:
    case TextToSpeech.LANG_COUNTRY_AVAILABLE:
    case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
        return true;

    default:/*from  ww  w  . j  a va2  s . co  m*/
        return false;
    }
}

From source file:Main.java

/**
 * get a descriptions of all the languages available as determined by
 * {@link TextToSpeech#isLanguageAvailable(Locale)}
 *//* w  w w  .ja  v  a2  s  .co m*/
public static String getLanguageAvailableDescription(TextToSpeech tts) {
    StringBuilder sb = new StringBuilder();
    for (Locale loc : Locale.getAvailableLocales()) {
        int availableCheck = tts.isLanguageAvailable(loc);
        sb.append(loc.toString()).append(" ");
        switch (availableCheck) {
        case TextToSpeech.LANG_AVAILABLE:
            break;
        case TextToSpeech.LANG_COUNTRY_AVAILABLE:
            sb.append("COUNTRY_AVAILABLE");
            break;
        case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
            sb.append("COUNTRY_VAR_AVAILABLE");
            break;
        case TextToSpeech.LANG_MISSING_DATA:
            sb.append("MISSING_DATA");
            break;
        case TextToSpeech.LANG_NOT_SUPPORTED:
            sb.append("NOT_SUPPORTED");
            break;
        }
        sb.append(NEW_LINE);
    }
    return sb.toString();
}

From source file:com.google.fpl.gim.examplegame.MainService.java

@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/*from  w  w w  .j  a  v  a2  s .c o  m*/
        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();
}

From source file:atlc.granadaaccessibilityranking.VoiceActivity.java

/**
 * Sets the locale for speech synthesis taking into account the language and country codes
 * If the <code>countryCode</code> is null, it just sets the language, if the
 * <code>languageCode</code> is null, it uses the default language of the device
 * If any of the codes are not valid, it uses the default language
 *
 * @param languageCode a String representing the language code, e.g. EN
 * @param countryCode a String representing the country code for the language used, e.g. US.
 * @throws Exception when the codes supplied cannot be used and the default locale is selected
 *//*from   w ww.  j  a v a  2  s .c  om*/
public void setLocale(String languageCode, String countryCode) throws Exception {
    if (languageCode == null) {
        setLocale();
        throw new Exception("Language code was not provided, using default locale");
    } else {
        if (countryCode == null)
            setLocale(languageCode);
        else {
            Locale lang = new Locale(languageCode, countryCode);
            if (myTTS.isLanguageAvailable(lang) == TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)
                myTTS.setLanguage(lang);
            else {
                setLocale();
                throw new Exception("Language or country code not supported, using default locale");
            }
        }
    }
}