Example usage for android.speech.tts TextToSpeech LANG_COUNTRY_AVAILABLE

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

Introduction

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

Prototype

int LANG_COUNTRY_AVAILABLE

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

Click Source Link

Document

Denotes the language is available for the language and country specified by the locale, but not the 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://  ww w . j a  v  a  2s  . com
        return false;
    }
}

From source file:Main.java

/**
 * get a descriptions of all the languages available as determined by
 * {@link TextToSpeech#isLanguageAvailable(Locale)}
 *//*  w ww  . java 2s. c  om*/
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.hichinaschool.flashcards.anki.ReadText.java

public static void textToSpeech(String text, long did, int ord, int qa) {
    mTextToSpeak = text;/*from www .  jav a  2  s. c  o  m*/
    mQuestionAnswer = qa;
    mDid = did;
    mOrd = ord;

    String language = getLanguage(mDid, mOrd, mQuestionAnswer);
    if (availableTtsLocales.isEmpty()) {
        Locale[] systemLocales = Locale.getAvailableLocales();
        for (Locale loc : systemLocales) {
            if (mTts.isLanguageAvailable(loc) == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
                availableTtsLocales.add(new String[] { loc.getISO3Language(), loc.getDisplayName() });
            }
        }
    }

    // Check, if stored language is available
    for (int i = 0; i < availableTtsLocales.size(); i++) {
        if (language.equals(NO_TTS)) {
            return;
        } else if (language.equals(availableTtsLocales.get(i)[0])) {
            speak(mTextToSpeak, language);
            return;
        }
    }

    // Otherwise ask
    Resources res = mReviewer.getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(mReviewer);
    if (availableTtsLocales.size() == 0) {
        builder.setTitle(res.getString(R.string.no_tts_available_title));
        builder.setMessage(res.getString(R.string.no_tts_available_message));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.ok), null);
    } else {
        ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
        final ArrayList<String> dialogIds = new ArrayList<String>();
        builder.setTitle(R.string.select_locale_title);
        // Add option: "no tts"
        dialogItems.add(res.getString(R.string.tts_no_tts));
        dialogIds.add(NO_TTS);
        for (int i = 0; i < availableTtsLocales.size(); i++) {
            dialogItems.add(availableTtsLocales.get(i)[1]);
            dialogIds.add(availableTtsLocales.get(i)[0]);
        }
        String[] items = new String[dialogItems.size()];
        dialogItems.toArray(items);

        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                MetaDB.storeLanguage(mReviewer, mDid, mOrd, mQuestionAnswer, dialogIds.get(which));
                speak(mTextToSpeak, dialogIds.get(which));
            }
        });
    }
    builder.create().show();
}

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/* ww  w  . j av  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:com.hughes.android.dictionary.DictionaryActivity.java

private void updateTTSLanguage(int i) {
    if (!ttsReady || index == null || textToSpeech == null) {
        Log.d(LOG, "Can't updateTTSLanguage.");
        return;/*  ww w. j a  v a  2s . c om*/
    }
    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();
    }
}