Example usage for android.speech.tts TextToSpeech LANG_NOT_SUPPORTED

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

Introduction

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

Prototype

int LANG_NOT_SUPPORTED

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

Click Source Link

Document

Denotes the language is not supported.

Usage

From source file:atlc.granadaaccessibilityranking.VoiceActivity.java

/**
 * Sets the locale for speech synthesis taking into account the language code
 * If the code is null or not valid, it uses the default language of the device
 *
 * @param languageCode a String representing the language code, e.g. EN
 * @throws Exception when the code supplied cannot be used and the default locale is selected
 *///from   w ww  . j av  a  2 s  .  co m
public void setLocale(String languageCode) throws Exception {
    if (languageCode == null) {
        setLocale();
        throw new Exception("Language code was not provided, using default locale");
    } else {
        Locale lang = new Locale(languageCode);
        if (myTTS.isLanguageAvailable(lang) != TextToSpeech.LANG_MISSING_DATA
                && myTTS.isLanguageAvailable(lang) != TextToSpeech.LANG_NOT_SUPPORTED)
            myTTS.setLanguage(lang);
        else {
            setLocale();
            throw new Exception("Language code not supported, using default locale");
        }
    }
}

From source file:com.example.app_2.activities.ImageGridActivity.java

@Override
public void onInit(int status) {
    int result;//from  w  ww.  j a v 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:org.tlhInganHol.android.klingonassistant.EntryActivity.java

public void onInit(int status) {
    // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
    if (status == TextToSpeech.SUCCESS) {
        // Set preferred language to Canadian Klingon.
        // Note that a language may not be available, and the result will indicate this.
        int result = mTts.setLanguage(new Locale("tlh", "", ""));
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            // Lanuage data is missing or the language is not supported.
            Log.e(TAG, "Language is not available.");
        } else {// ww  w  .j av a  2 s.  c om
            // Check the documentation for other possible result codes.
            // For example, the language may be available for the locale,
            // but not for the specified country and variant.

            // The TTS engine has been successfully initialized.
            ttsInitialized = true;
            if (mSpeakButton != null) {
                // Log.d(TAG, "enabling TTS button in onInit");
                mSpeakButton.setVisible(true);
            }
        }
    } else {
        // Initialization failed.
        Log.e(TAG, "Could not initialize TextToSpeech.");
    }
}

From source file:com.lofland.housebot.BotController.java

@Override
public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {

        int result = tts.setLanguage(Locale.US);

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } else {/* w ww. j  a  va  2s  .c  o m*/
            btnSpeak.setEnabled(true);
            speakOut();
        }
    } else {
        Log.e("TTS", "Initilization Failed!");
    }

}

From source file:com.air.mobilebrowser.BrowserActivity.java

@SuppressWarnings("deprecation")
@Override/*from   w  ww  .j  av a 2  s  . co m*/
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {

        int result = ttsPlayer.getTextToSpeech().setLanguage(Locale.US);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e(TAG, "Language data missing or not supported");
            mDeviceStatus.ttsEngineStatus = DeviceStatus.TTS_ENGINE_STATUS_UNAVAILABLE;
        } else {
            mDeviceStatus.ttsEngineStatus = DeviceStatus.TTS_ENGINE_STATUS_IDLE;
        }
    } else {
        Log.e(TAG, "Unable to initialize TextToSpeech (status: " + status + ")");
        mDeviceStatus.ttsEngineStatus = DeviceStatus.TTS_ENGINE_STATUS_UNAVAILABLE;
    }

    // Notification of completion comes in on different thread, currently
    // UI updates necessary in executeAIRMobileFunction
    super.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            JSONObject jsonToSend = new JSONObject();

            try {
                jsonToSend.put(JSKeys.TTS_ENABLED, mDeviceStatus.ttsEnabled);
                jsonToSend.put(JSKeys.TTS_ENGINE_STATUS, mDeviceStatus.ttsEngineStatus);
                executeAIRMobileFunction(JSNTVCmds.NTV_ON_TTS_ENABLED, jsonToSend.toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

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 .ja v  a 2  s.  co  m
 */
@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();
            }
        }
    }
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

@Override
public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {

        Locale locale = null;//from  w w  w . j  av  a  2 s  .  c om
        VoiceConfig voice = MainActivity.voice;
        if (voice != null && voice.language != null && voice.language.length() > 0) {
            locale = new Locale(voice.language);
        } else {
            locale = Locale.US;
        }
        int result = this.tts.setLanguage(locale);

        float pitch = 1;
        if (voice != null && voice.pitch != null && voice.pitch.length() > 0) {
            try {
                pitch = Float.valueOf(voice.pitch);
            } catch (Exception exception) {
            }
        }
        float speechRate = 1;
        if (voice != null && voice.speechRate != null && voice.speechRate.length() > 0) {
            try {
                speechRate = Float.valueOf(voice.speechRate);
            } catch (Exception exception) {
            }
        }
        this.tts.setPitch(pitch);
        this.tts.setSpeechRate(speechRate);

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        }

        this.tts.setOnUtteranceCompletedListener(this);

    } else {
        Log.e("TTS", "Initilization Failed!");
    }

}

From source file:com.updetector.MainActivity.java

@Override
//of TextToSpeech
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        // set Language
        int result = mTextToSpeech.setLanguage(Locale.US);
        // tts.setPitch(5); // set pitch level
        // tts.setSpeechRate(2); // set speech speed rate
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
        }/*from   ww w  .  j av  a  2s  . c o  m*/
        {
            Log.e(LOG_TAG, "Text-To-Speech Language cannot be setted US. Error code=" + result);
        }
        //mTextToSpeech.speak("test", TextToSpeech.QUEUE_FLUSH, null);
    } else {
        Log.e(LOG_TAG, "Text-To-Speech Initilization Failed");
    }
}