Example usage for android.speech.tts TextToSpeech ERROR

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

Introduction

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

Prototype

int ERROR

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

Click Source Link

Document

Denotes a generic operation failure.

Usage

From source file:com.example.michel.facetrack.FaceTrackerActivity.java

/**
 * Initializes the UI and initiates the creation of a face detector.
 *///from w  ww . j  a v a2 s . c  o  m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource();
    } else {
        requestCameraPermission();
    }

    mTTS = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                mTTS.setLanguage(Locale.CANADA);
                //                    mTTS.setOnUtteranceCompletedListener(new TextToSpeech.OnUtteranceCompletedListener() {
                //                        @Override
                //                        public void onUtteranceCompleted(String utteranceId) {
                //                            startSpeechToText();
                //                        }
                //                    });
                String toSpeak = "Blind spot opened. What do you want?";
                mTTS.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                waitStartSTT(8000);

            }

        }
    });

    /*mPreview.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mCameraSource.takePicture(new CameraSource.ShutterCallback() {
            @Override
            public void onShutter() {
            
            }
        }, new CameraSource.PictureCallback() {
            @Override
            public void onPictureTaken(byte[] bytes) {
                String file_timestamp = Long.toString(System.currentTimeMillis());
                Log.e("File: ", Environment.getExternalStorageDirectory() + "/" + file_timestamp + ".jpg");
                final File file = new File(Environment.getExternalStorageDirectory() + "/" + file_timestamp + ".jpg");
                try {
                    save(bytes, file);
            
                    String toSpeak = "Image saved";
                    mTTS.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    Toast.makeText(FaceTrackerActivity.this, "Saved to " + Environment.getExternalStorageDirectory() + "/" + file_timestamp + ".jpg", Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            
            private void save(byte[] bytes, final File file) throws IOException {
                OutputStream output = null;
                try {
                    output = new FileOutputStream(file);
                    output.write(bytes);
                } finally {
                    if (null != output) {
                        output.close();
                    }
                }
                Float happiness = sendPhotoToAzure(file); // Sending a blob (photo) to the Azure Storage
                String photo_url = "https://blindspot.blob.core.windows.net/image/" + file.getName();
                Log.e("Photo_url : ", photo_url);
    //                        Float happiness = getHappiness(photo_url); // Call the Microsoft's Emotion API using the photo url
                Log.e("Happiness: ", Float.toString(happiness));
            }
        });
    }
    });*/

    lastFaceTime = System.currentTimeMillis();

}

From source file:net.bible.service.device.speak.TextToSpeechController.java

@Override
public void onInit(int status) {
    Log.d(TAG, "Tts initialised");
    boolean isOk = false;

    // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
    if (mTts != null && status == TextToSpeech.SUCCESS) {
        Log.d(TAG, "Tts initialisation succeeded");
        boolean localeOK = false;
        Locale locale = null;//from  w  w  w  . jav a2s.  com
        for (int i = 0; i < localePreferenceList.size() && !localeOK; i++) {
            locale = localePreferenceList.get(i);
            Log.d(TAG, "Checking for locale:" + locale);
            int result = mTts.setLanguage(locale);
            localeOK = ((result != TextToSpeech.LANG_MISSING_DATA)
                    && (result != TextToSpeech.LANG_NOT_SUPPORTED));
            if (localeOK) {
                Log.d(TAG, "Successful locale:" + locale);
                currentLocale = locale;
            }
        }

        if (!localeOK) {
            Log.e(TAG, "TTS missing or not supported");
            // Language data is missing or the language is not supported.
            ttsLanguageSupport.addUnsupportedLocale(locale);
            showError(R.string.tts_lang_not_available);
        } else {
            // The TTS engine has been successfully initialized.
            ttsLanguageSupport.addSupportedLocale(locale);
            int ok = mTts.setOnUtteranceCompletedListener(this);
            if (ok == TextToSpeech.ERROR) {
                Log.e(TAG, "Error registering onUtteranceCompletedListener");
            } else {
                // everything seems to have succeeded if we get here
                isOk = true;
                // say the text
                startSpeaking();

                // add event listener to stop on call
                stopIfPhoneCall();
            }
        }
    } else {
        Log.d(TAG, "Tts initialisation failed");
        // Initialization failed.
        showError(R.string.error_occurred);
    }

    if (!isOk) {
        shutdown();
    }
}

From source file:com.bellman.bible.service.device.speak.TextToSpeechController.java

@Override
public void onInit(int status) {
    Log.d(TAG, "Tts initialised");
    boolean isOk = false;

    // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
    if (mTts != null && status == TextToSpeech.SUCCESS) {
        Log.d(TAG, "Tts initialisation succeeded");
        boolean localeOK = false;
        Locale locale = null;/*from  w  ww  .  j  a  v a 2  s .c  o  m*/
        for (int i = 0; i < localePreferenceList.size() && !localeOK; i++) {
            locale = localePreferenceList.get(i);
            Log.d(TAG, "Checking for locale:" + locale);
            int result = mTts.setLanguage(locale);
            localeOK = ((result != TextToSpeech.LANG_MISSING_DATA)
                    && (result != TextToSpeech.LANG_NOT_SUPPORTED));
            if (localeOK) {
                Log.d(TAG, "Successful locale:" + locale);
                currentLocale = locale;
            }
        }

        if (!localeOK) {
            Log.e(TAG, "TTS missing or not supported");
            // Language data is missing or the language is not supported.
            ttsLanguageSupport.addUnsupportedLocale(locale);
            showError(R.string.tts_lang_not_available, new Exception("Tts missing or not supported"));
        } else {
            // The TTS engine has been successfully initialized.
            ttsLanguageSupport.addSupportedLocale(locale);
            int ok = mTts.setOnUtteranceCompletedListener(this);
            if (ok == TextToSpeech.ERROR) {
                Log.e(TAG, "Error registering onUtteranceCompletedListener");
            } else {
                // everything seems to have succeeded if we get here
                isOk = true;
                // say the text
                startSpeaking();

                // add event listener to stop on call
                stopIfPhoneCall();
            }
        }
    } else {
        Log.d(TAG, "Tts initialisation failed");
        // Initialization failed.
        showError(R.string.error_occurred, new Exception("Tts Initialisation failed"));
    }

    if (!isOk) {
        shutdown();
    }
}

From source file:com.microsoft.mimickeralarm.mimics.MimicWithForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_forecast_weather_mimic, container, false);
    ProgressButton progressButton = (ProgressButton) view.findViewById(R.id.capture_button);
    progressButton.setReadyState(ProgressButton.State.ReadyAudio);

    mStateManager = new MimicStateManager();
    mStateManager.registerCountDownTimer((CountDownTimerView) view.findViewById(R.id.countdown_timer),
            TIMEOUT_MILLISECONDS);
    mStateManager.registerStateBanner((MimicStateBanner) view.findViewById(R.id.mimic_state));
    mStateManager.registerProgressButton(progressButton, MimicButtonBehavior.AUDIO);
    mStateManager.registerMimic(this);
    mTextResponse = (TextView) view.findViewById(R.id.understood_text);
    mTextResponse.setOnClickListener(this);

    myTTS = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override//from  w  ww .j a  va2s. c o  m
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                myTTS.setLanguage(Locale.KOREAN);
            }
        }
    });

    //        Button finishButton = (Button) view.findViewById(R.id.fin_button);
    //        Bundle args = getArguments();
    //        mShareableUri = args.getString("shareable-uri");
    //
    //        // Set up timer to dismiss the sharing fragment if there is no user interaction with the buttons
    //        mSharingFragmentDismissTask = new Runnable() {
    //            @Override
    //            public void run() {
    //                finishShare();
    //            }
    //        };
    //        mHandler = new Handler();
    return view;
}

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 . ja va 2 s  . c  o m*/
}

From source file:com.application.akscorp.yandextranslator2017.TranslateScreen.java

/**
 * Start component init(initialization)/*from   w  w  w .j av a2s . c  om*/
 */
private void StartInit() {
    //Init speech object
    SpeechEngine = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                SpeechEngine.setLanguage(Locale.UK);
            }
        }
    });

    ImageButton ExchangeBtn = (ImageButton) TranslateScreen.findViewById(R.id.exchange_languages);
    ExchangeBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ExchangeTranslateLanguages();
        }
    });

    CopyButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CopyTextToClipBoard(GetTranslate());
        }
    });
    SpeakButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (SpeechEngine.isSpeaking())
                SpeechEngine.stop();
            else {
                try {
                    TextToSpeech(GetTranslate(), new Locale(LangsCodeSpinner[ToLang]));
                } catch (Exception e) {
                    Logs.SaveLog(context, e);
                    Toast.makeText(context, LanguageWork.GetResourceString(context, "forbidden_option"),
                            Toast.LENGTH_SHORT).show();
                }
            }
        }
    });
    editTextInputFrazeForTranslate = (EditTextWithButtons) TranslateScreen.findViewById(R.id.translate_input);
    AddToFavourite = (ImageButton) TranslateScreen.findViewById(R.id.add_favourite_button);
    TranslateAdapter = new TranslateListViewAdapter(context);
    TranslateList.setAdapter(TranslateAdapter);
    MyUtility.setListViewHeightBasedOnChildren(TranslateList);

    TranslateButtonController();
    InitLanguagesTranslateList();

}

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  w w. ja v  a 2 s. c om*/
}

From source file:org.apache.cordova.plugins.speech.TTS.java

/**
 * Called when the TTS service is initialized.
 *
 * @param status/*from   w w w. j ava 2 s.  com*/
 */
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        Log.d(LOG_TAG, "TextToSpeech init succeeded");

        state = TTS.STARTED;
        PluginResult result = new PluginResult(PluginResult.Status.OK, TTS.STARTED);
        result.setKeepCallback(false);
        this.callbackContext.sendPluginResult(result);

        // Default Lang US
        mTts.setLanguage(Locale.US);

        if (Build.VERSION.SDK_INT >= 15) {
            mTts.setOnUtteranceProgressListener(new TTSProgressListener(this.callbackContext));
        } else {
            mTts.setOnUtteranceCompletedListener(new TTSCompletedListener(this.callbackContext));
        }
    } else if (status == TextToSpeech.ERROR) {
        Log.d(LOG_TAG, "TextToSpeech init error");
        state = TTS.STOPPED;
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, TTS.STOPPED);
        result.setKeepCallback(false);
        this.callbackContext.sendPluginResult(result);
    }
}

From source file:com.phonegap.plugins.speech.TTS.java

/**
 * Called when the TTS service is initialized.
 *
 * @param status/* w  w w  .java  2 s .  c o  m*/
 */
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);
        this.startupCallbackContext.sendPluginResult(result);
        mTts.setOnUtteranceCompletedListener(this);
        //            Putting this code in hear as a place holder. When everything moves to API level 15 or greater
        //            we'll switch over to this way of trackign progress.
        //            mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
        //
        //                @Override
        //                public void onDone(String utteranceId) {
        //                    Log.d(LOG_TAG, "got completed utterance");
        //                    PluginResult result = new PluginResult(PluginResult.Status.OK);
        //                    result.setKeepCallback(false);
        //                    callbackContext.sendPluginResult(result);        
        //                }
        //
        //                @Override
        //                public void onError(String utteranceId) {
        //                    Log.d(LOG_TAG, "got utterance error");
        //                    PluginResult result = new PluginResult(PluginResult.Status.ERROR);
        //                    result.setKeepCallback(false);
        //                    callbackContext.sendPluginResult(result);        
        //                }
        //
        //                @Override
        //                public void onStart(String utteranceId) {
        //                    Log.d(LOG_TAG, "started talking");
        //                }
        //                
        //            });
    } else if (status == TextToSpeech.ERROR) {
        state = TTS.STOPPED;
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, TTS.STOPPED);
        result.setKeepCallback(false);
        this.startupCallbackContext.sendPluginResult(result);
    }
}

From source file:com.firerunner.cordova.TTS.java

/**
 * Called when the TTS service is initialized.
 *
 * @param status/* w  ww  . j  a  v  a2s.co  m*/
 */
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        state = TTS.STARTED;

        //Voice v = mTts.getVoice();
        //v.

        PluginResult result = new PluginResult(PluginResult.Status.OK, TTS.STARTED);
        result.setKeepCallback(false);
        //this.success(result, this.startupCallbackId);
        this.startupCallbackContext.sendPluginResult(result);
        mTts.setOnUtteranceCompletedListener(this);
        //            Putting this code in hear as a place holder. When everything moves to API level 15 or greater
        //            we'll switch over to this way of trackign progress.
        //            mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
        //
        //                @Override
        //                public void onDone(String utteranceId) {
        //                    Log.d(LOG_TAG, "got completed utterance");
        //                    PluginResult result = new PluginResult(PluginResult.Status.OK);
        //                    result.setKeepCallback(false);
        //                    callbackContext.sendPluginResult(result);        
        //                }
        //
        //                @Override
        //                public void onError(String utteranceId) {
        //                    Log.d(LOG_TAG, "got utterance error");
        //                    PluginResult result = new PluginResult(PluginResult.Status.ERROR);
        //                    result.setKeepCallback(false);
        //                    callbackContext.sendPluginResult(result);        
        //                }
        //
        //                @Override
        //                public void onStart(String utteranceId) {
        //                    Log.d(LOG_TAG, "started talking");
        //                }
        //                
        //            });
    } else if (status == TextToSpeech.ERROR) {
        state = TTS.STOPPED;
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, TTS.STOPPED);
        result.setKeepCallback(false);
        this.startupCallbackContext.sendPluginResult(result);
    }
}