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.vaporwarecorp.mirror.feature.texttospeech.TextToSpeechManagerImpl.java

@Override
public void onFeatureResume() {
    mTextToSpeech = new TextToSpeech(mAppManager.getAppContext(), status -> {
        if (status == TextToSpeech.SUCCESS) {
            mTextToSpeech.setLanguage(Locale.US);
        } else {/*from w  w  w  .ja  v a2 s. co m*/
            mTextToSpeech = null;
        }
    });
}

From source file:com.wordsbaking.cordova.tts.TTS.java

@Override
public void onInit(int status) {
    if (status != TextToSpeech.SUCCESS) {
        tts = null;/*from ww w .  j a  v a 2 s .  c o  m*/
    } else {
        // warm up the tts engine with an empty string
        HashMap<String, String> ttsParams = new HashMap<String, String>();
        ttsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "");
        tts.setLanguage(new Locale("en", "US"));
        tts.speak("", TextToSpeech.QUEUE_FLUSH, ttsParams);

        ttsInitialized = true;
    }
}

From source file:com.rsamadhan.DomainListFragment.java

/**
 * Called to signal the completion of the TextToSpeech engine initialization.
 *
 * @param status {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
 *///  w w  w.j  a va  2  s  .com
@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = tts
                .setLanguage(ApplicationUtils.getSelectedLocale(PreferenceManager.getInstance(getActivity())));
        tts.setPitch(0.6f);
        tts.setSpeechRate(0.5f);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Toast.makeText(getActivity(), getString(R.string.speech_not_supported), Toast.LENGTH_LONG).show();
        } else {
            isTTSSuccess = true;

            speakOut();
        }
    }
}

From source file:com.guanqing.hao.OcrCaptureActivity.java

private void init() {
    mDimView = findViewById(R.id.dim_view);
    final CameraSourcePreview preview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);
    mDict = new Dict(this);

    mCameraSourceHelper = new CameraSourceHelper(this, preview, mGraphicOverlay, mDict);

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, mCameraSourceHelper);

    // Set up the Text To Speech engine.
    TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
        @Override/*  w  w  w.j  ava  2 s  .c o  m*/
        public void onInit(final int status) {
            if (status == TextToSpeech.SUCCESS) {
                tts.setLanguage(Locale.US);
            }
        }
    };
    tts = new TextToSpeech(this.getApplicationContext(), listener);
}

From source file:com.xengar.android.englishverbs.ui.UniversalFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getArguments() != null) {
        verbsType = getArguments().getString(VERB_TYPE, BOTH);
        itemType = getArguments().getString(ITEM_TYPE, LIST);
        sortTYpe = getArguments().getString(SORT_TYPE, ALPHABET);
    }/*  ww w  . j  a  v  a  2s  . c  o m*/

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_universal, container, false);

    mCustomErrorView = (CustomErrorView) view.findViewById(R.id.error);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler);
    progressBar = (CircularProgressBar) view.findViewById(R.id.progressBar);
    mVerbs = new ArrayList<>();

    // initialize Speaker
    tts = new TextToSpeech(getContext(), new TextToSpeech.OnInitListener() {
        @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) {
                    if (LOG) {
                        Log.e("TTS", "This Language is not supported");
                    }
                }
            } else {
                if (LOG) {
                    Log.e("TTS", "Initilization Failed!");
                }
            }
        }
    });
    mAdapter = new VerbAdapter(mVerbs, itemType, tts);

    return view;
}

From source file:ai.api.lejossample.MainActivity.java

private void initTTS() {
    ttsEngine = new TextToSpeech(this, new OnInitListener() {
        @Override/*w w w  .j  a v  a2  s  .c  om*/
        public void onInit(int initStatus) {
            if (initStatus == TextToSpeech.SUCCESS) {
                ttsEngine.setLanguage(Locale.US);
                ttsReady = true;
            } else {
                Log.d(TAG, "Can't initialize TextToSpeech");
            }

        }
    });
}

From source file:com.perchtech.humraz.blind.OcrCaptureActivity.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.ocr_capture);
    Speech.getInstance().say("You Are Now In Character Recognition Mode.");
    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);

    boolean autoFocus = true;
    boolean useFlash = false;

    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {//from w  w w .ja  v a  2  s . c o m
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();

    TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(final int status) {
            if (status == TextToSpeech.SUCCESS) {
                Log.d("OnInitListener", "Text to speech engine started successfully.");
                tts.setLanguage(Locale.US);
            } else {
                Log.d("OnInitListener", "Error starting the text to speech engine.");
            }
        }
    };
    tts = new TextToSpeech(this.getApplicationContext(), listener);
}

From source file:com.nbplus.vbroadlauncher.BaseActivity.java

@Override
public void onInit(int status) {
    Log.d(TAG, "> TTS onInit()");

    LauncherSettings.getInstance(this).setIsCheckedTTSEngine(true);
    if (status != TextToSpeech.SUCCESS) {
        Log.e(TAG, String.format("TextToSpeechManager.onInit(%d) fail!", status));
        Log.d(TAG, "   ??.... ? ??...");
        if (mcheckText2SpeechLister != null) {
            mcheckText2SpeechLister.onCheckResult(null);
            if (mText2Speech != null)
                mText2Speech.shutdown();
            mText2Speech = null;/*from   ww w .  jav a 2s.c om*/
        }
        showText2SpeechAlertDialog();
    } else {
        int result = mText2Speech.setLanguage(Locale.KOREA);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e(TAG, String.format("TextToSpeech.setLanguage(%s) fail!", Locale.KOREA.getDisplayName()));
            Log.d(TAG, "   ??.... ? ??...");
            if (mcheckText2SpeechLister != null) {
                mcheckText2SpeechLister.onCheckResult(null);
                if (mText2Speech != null)
                    mText2Speech.shutdown();
                mText2Speech = null;
            }
            showText2SpeechAlertDialog();
        } else {
            if (mcheckText2SpeechLister != null) {
                mcheckText2SpeechLister.onCheckResult(mText2Speech);
            } else {
                if (mcheckText2SpeechLister != null) {
                    mcheckText2SpeechLister.onCheckResult(null);
                    if (mText2Speech != null)
                        mText2Speech.shutdown();
                    mText2Speech = null;
                }
            }
        }
    }
}

From source file:in.codehex.arrow.MainActivity.java

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        textToSpeech.setLanguage(Locale.getDefault());
        textToSpeech.setPitch(0.8f);/* w w w . j  ava 2  s.  co  m*/
        textToSpeech.setSpeechRate(0.8f);
    }
}

From source file:com.ct.speech.TTS.java

/**
 * Called when the TTS service is initialized.
 * /*from  ww w. j a  v a  2  s.  c o  m*/
 * @param status 
 */
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        state = TTS.STARTED;
        PluginResult result = new PluginResult(PluginResult.Status.OK, TTS.STARTED);
        result.setKeepCallback(false);
        this.success(result, this.startupCallbackId);
    } else if (status == TextToSpeech.ERROR) {
        state = TTS.STOPPED;
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, TTS.STOPPED);
        result.setKeepCallback(false);
        this.error(result, this.startupCallbackId);
    }
}