Example usage for android.speech.tts TextToSpeech LANG_AVAILABLE

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

Introduction

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

Prototype

int LANG_AVAILABLE

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

Click Source Link

Document

Denotes the language is available for the language by the locale, but not the country and variant.

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://  w ww  . j  a v a 2s . co m
        return false;
    }
}

From source file:Main.java

/**
 * get a descriptions of all the languages available as determined by
 * {@link TextToSpeech#isLanguageAvailable(Locale)}
 *//*from w ww  .ja va2s .  com*/
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:org.thecongers.mcluster.MainActivity.java

public void onInit(int initStatus) {
    if (initStatus == TextToSpeech.SUCCESS) {
        if (text2speech.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
            text2speech.setLanguage(Locale.US);
    } else if (initStatus == TextToSpeech.ERROR) {
        Log.d(TAG, "Text to Speech startup failed...");
    }//w w  w.  jav a2  s.c o  m
}

From source file:com.eng.arab.translator.androidtranslator.ShowDetailsMonth.java

public void onInit(int initStatus) {

    //check for successful instantiation
    if (initStatus == TextToSpeech.SUCCESS) {
        if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
            myTTS.setLanguage(Locale.US);
    } else if (initStatus == TextToSpeech.ERROR) {
        Toast.makeText(getApplicationContext(), "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
    }// w ww .  j a v  a2s . c om
}

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//w  w w.  j  a v a2s.co 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:com.example.app_2.activities.ImageGridActivity.java

@Override
public void onInit(int status) {
    int result;/*from w  w w. jav  a2 s  .c om*/
    if (status == TextToSpeech.SUCCESS) {
        Locale pol_loc = new Locale("pl", "pl_PL");
        if (TextToSpeech.LANG_AVAILABLE == tts.isLanguageAvailable(pol_loc)) {
            result = tts.setLanguage(pol_loc);
            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Log.e("TTS", "LANG_NOT_SUPPORTED");
            }
        } else {
            result = tts.setLanguage(Locale.ENGLISH);
        }
    } else {
        Log.e("TTS", "Initialization Failed");
    }
}

From source file:com.hughes.android.dictionary.DictionaryActivity.java

private void updateTTSLanguage(int i) {
    if (!ttsReady || index == null || textToSpeech == null) {
        Log.d(LOG, "Can't updateTTSLanguage.");
        return;//from w w w  . ja v  a  2  s  .co  m
    }
    final Locale locale = new Locale(dictionary.indices.get(i).sortLanguage.getIsoCode());
    Log.d(LOG, "Setting TTS locale to: " + locale);
    try {
        final int ttsResult = textToSpeech.setLanguage(locale);
        if (ttsResult != TextToSpeech.LANG_AVAILABLE && ttsResult != TextToSpeech.LANG_COUNTRY_AVAILABLE) {
            Log.e(LOG, "TTS not available in this language: ttsResult=" + ttsResult);
        }
    } catch (Exception e) {
        Toast.makeText(this, getString(R.string.TTSbroken), Toast.LENGTH_LONG).show();
    }
}

From source file:com.gelakinetic.mtgfam.fragments.LifeCounterFragment.java

/**
 * When mTts is initialized, set the boolean flag and display the option in the ActionBar
 *
 * @param status SUCCESS or ERROR./*from w w  w .  j a va 2  s . c om*/
 */
@Override
public void onInit(final int status) {
    if (isAdded()) {
        if (status == TextToSpeech.SUCCESS) {
            int result;
            try {
                result = mTts.setLanguage(getResources().getConfiguration().locale);
            } catch (IllegalArgumentException e) {
                /* This is a new exception on Samsung devices, setting the language isn't necessary */
                result = TextToSpeech.LANG_AVAILABLE;
            }
            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                FamiliarActivity activity = getFamiliarActivity();
                if (activity != null) {
                    activity.showTtsDialog();
                }
            } else {
                mTtsInit = true;
                if (mIsSearchViewOpen) {
                    /* Search view is open, pend menu refresh */
                    mAfterSearchClosedRunnable = new Runnable() {
                        @Override
                        public void run() {
                            getActivity().invalidateOptionsMenu();
                        }
                    };
                } else {
                    /* Redraw menu */
                    getActivity().invalidateOptionsMenu();
                }
            }
        } else if (status == TextToSpeech.ERROR) {
            FamiliarActivity activity = getFamiliarActivity();
            if (activity != null) {
                activity.showTtsDialog();
            }
        }
    }
}