Example usage for android.speech.tts TextToSpeech SUCCESS

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

Introduction

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

Prototype

int SUCCESS

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

Click Source Link

Document

Denotes a successful operation.

Usage

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./* ww w. j av  a2  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();
            }
        }
    }
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

@SuppressWarnings("deprecation")
public void onTextToSpeechInit(int status) {

    this.ttsAvailable = (status == TextToSpeech.SUCCESS) && !Configuration.IS_NOOK_TOUCH;

    if (this.ttsAvailable) {
        this.textToSpeech.setOnUtteranceCompletedListener(this::onStreamingCompleted);
    } else {// ww  w  .ja  v a  2s  .c o m
        LOG.info("Failed to initialize TextToSpeech. Got status " + status);
    }
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

@SuppressWarnings("deprecation")
public void onTextToSpeechInit(int status) {

    this.ttsAvailable = (status == TextToSpeech.SUCCESS) && !Configuration.IS_NOOK_TOUCH;

    if (this.ttsAvailable) {
        this.textToSpeech.setOnUtteranceCompletedListener(this);
    }//from  w w w.jav  a2s . c o  m
}

From source file:bikebadger.RideFragment.java

public void onInit(int initStatus) {
    // assert  (false);
    //check for successful instantiation
    if (initStatus == TextToSpeech.SUCCESS) {
        //if(RideManager.mTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
        //  RideManager.mTTS.setLanguage(Locale.US);
    } else if (initStatus == TextToSpeech.ERROR) {
        Toast.makeText(mRideManager.mAppContext, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
        AlertDialog ad = new AlertDialog.Builder(getActivity()).create();
        ad.setCancelable(false);/*from  w  w  w.  j  a va 2s  . c om*/
        ad.setTitle("Text To Speech Engine Not Found");
        ad.setMessage(
                "There was a problem finding the Text To Speech Engine. Make sure it's install properly under Language and Input Settings.");
        ad.setButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        ad.show();
    }
}

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

@Override
public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {

        Locale locale = null;/*  w ww  . j  a va2 s .  com*/
        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) {
        }/*  w  ww. j av a  2  s.  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");
    }
}