@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_pt_br) { Locale locale = new Locale("pt", "BR"); tts.setLanguage(locale); return true; } else if (id == R.id.action_en_us) { Locale locale = Locale.ENGLISH; tts.setLanguage(locale); return true; } else if (id == R.id.action_check_data) { // Verifica se o pacote de dados do TTS está instalado Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkIntent, ACTION_CHECK_DATA_CODE); return true; } else if (id == R.id.action_install_data) { // Instala o pacote de dados Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); return true; } return super.onOptionsItemSelected(item); }
@Override public void onInit(int status) { int result; if (status == TextToSpeech.SUCCESS) { Locale[] AvalLoc = Locale.getAvailableLocales(); Log.i("TTS", "Available locales " + Arrays.toString(AvalLoc)); Locale pol_loc = new Locale("en", "EN"); if (TextToSpeech.LANG_AVAILABLE == tts.isLanguageAvailable(pol_loc)) { result = tts.setLanguage(pol_loc); } else { result = tts.setLanguage(Locale.ITALIAN); } if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "LANG_NOT_SUPPORTED"); } else { btnSpeak.setEnabled(true); speakOut(); } } else { Log.e("TTS", "Initialization Failed"); } }
@Override public void onInit(int status) { // Set language to use for playing text if (status == TextToSpeech.SUCCESS) { int result = textToSpeech.setLanguage(Locale.US); } }
// Implements TextToSpeech.OnInitListener. public void onInit(int status) { // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. if (status == TextToSpeech.SUCCESS) { // Set preferred language to US english. // Note that a language may not be available, and the result will indicate this. int result = mTts.setLanguage(Locale.US); // Try this someday for some interesting results. // int result mTts.setLanguage(Locale.FRANCE); 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 { // 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. // Allow the user to press the button for the app to speak again. mAgainButton.setEnabled(true); // Greet the user. sayHello(); } } else { // Initialization failed. Log.e(TAG, "Could not initialize TextToSpeech."); } }
@Override // OnInitListener (called when textToSpeech is initialised) public void onInit(int status) { if (BuildConfig.DEBUG) Log.d(engSpaActivity.getTag(), "EngSpaFragment.onInit()"); engSpaActivity.setProgressBarVisible(false); this.statusTextView.setText(""); if (status == TextToSpeech.SUCCESS) { if (this.textToSpeech == null) { // this could happen if activity is paused between creating // new textToSpeech and getting the response back here this.statusTextView.setText("textToSpeech closed down"); return; } int result = textToSpeech.setLanguage(LOCALE_ES); if (BuildConfig.DEBUG) { Log.d(engSpaActivity.getTag(), "textToSpeech.setLanguage(); result=" + result); } if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { this.statusTextView.setText("TextToSpeech for Spanish is not supported"); } if (this.spanish != null) speakSpanish2(); } else { Log.w(engSpaActivity.getTag(), "EngSpaFragment.onInit(" + status + ")"); this.statusTextView.setText( "Initilization of textToSpeech failed! Have you installed text-to-speech?"); } }
@Override public void onInit(int status) { // TODO Auto-generated method stub if (status != TextToSpeech.ERROR) { t1.setLanguage(Locale.UK); } }
private void displayAlert(String displayMessage) { alertMessage.setMessage(displayMessage); if (TTS == 1) { talker.setLanguage(Locale.US); talker.speak(displayMessage, TextToSpeech.QUEUE_ADD, null); } alertMessage.show(); }
@Override public void onInit(int status) { Log.i(TAG, "onInit "); if (status == TextToSpeech.SUCCESS && textToSpeech != null) { textToSpeech.setLanguage(Locale.ENGLISH); Log.i(TAG, "Local root: " + Locale.getDefault().getCountry()); checkStartTextToSpeech = true; Log.i(TAG, "onInit SUCCESS"); } }
public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { final int result = mTts.setLanguage(Locale.US); mTts.setSpeechRate(0.9F); mTts.setPitch(0.9F); if (result != TextToSpeech.LANG_MISSING_DATA && result != TextToSpeech.LANG_NOT_SUPPORTED) { mTts.speak(spokenText, TextToSpeech.QUEUE_FLUSH, null); } } }
@Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS && mTts != null) { Log.i("TTS initialized!"); mTts.setLanguage(mLocale); mTtsAvailable = true; } else { Log.e("Can't initialise TTS!"); mTtsAvailable = false; } }
@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 { Log.e("TTS", "Initilization Failed!"); } }
@Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.getDefault()); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); } } }
/** TTS */ @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { Log.i(Globals.LOG_TAG, "TTS enabled."); int langResult = tts.setLanguage(Locale.getDefault()); if (langResult == TextToSpeech.LANG_MISSING_DATA || langResult == TextToSpeech.LANG_NOT_SUPPORTED) { Log.i(Globals.LOG_TAG, "TTS not available for this locale."); } } else { Log.i(Globals.LOG_TAG, "TTS failed to initialize."); } }
@Override public void onInit(int status) { // TODO Auto-generated method stub Locale loc = new Locale("uk"); SharedPreferences setting = getSharedPreferences("wordroid.model_preferences", MODE_PRIVATE); if (setting.getString("category", "1").equals("2")) loc = new Locale("us"); /* 检查是否支持输入的时区 */ if (tts.isLanguageAvailable(loc) == TextToSpeech.LANG_AVAILABLE) { /* 设定语言 */ tts.setLanguage(loc); } tts.setOnUtteranceCompletedListener(ttsUtteranceCompletedListener); }
@Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { // TODO: check if the language is available Locale ttsLanguage; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { ttsLanguage = tts.getDefaultLanguage(); } else { ttsLanguage = tts.getLanguage(); } if (ttsLanguage == null) { ttsLanguage = Locale.US; } int supportStatus = tts.setLanguage(ttsLanguage); switch (supportStatus) { case TextToSpeech.LANG_MISSING_DATA: case TextToSpeech.LANG_NOT_SUPPORTED: tts.shutdown(); tts = null; Log.e(TAG, "TTS Language data is not available."); Toast.makeText(context, "Unable to set 'Text to Speech' language!", Toast.LENGTH_LONG) .show(); break; } if (tts != null) { tts.setOnUtteranceCompletedListener(mSpeechCompleteListener); // Register the broadcast receiver for the speech output period // updates LocalBroadcastManager.getInstance(context) .registerReceiver( mSpeechIntervalUpdateReceiver, new IntentFilter(SettingsFragment.ACTION_UPDATED_STATUS_PERIOD)); } } else { // Notify the user that the tts engine is not available. Log.e(TAG, "TextToSpeech initialization failed."); Toast.makeText( context, "Please make sure 'Text to Speech' is enabled in the " + "system accessibility settings.", Toast.LENGTH_LONG) .show(); } }
@Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { txtS.setLanguage(Locale.US); txtS.setSpeechRate(.8f); /* if(Build.VERSION.SDK_INT>20){ Voice v = new Voice("v1", Locale.US, Voice.QUALITY_VERY_HIGH, Voice.LATENCY_NORMAL, false, false ); } // txtS.setVoice() // txtS.setVoice(new Voice(Voice.QUALITY_VERY_HIGH);' */ } }
@Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { ttsLoaded = true; tts.setSpeechRate(0.8f); } int temp = tts.setLanguage(Locale.US); if (temp == TextToSpeech.LANG_MISSING_DATA || temp == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e(TAG, "Language is not available."); ttsLoaded = false; } // Initialize view pager initializePager(); }
/** Called when TTS is ready. */ protected void onTtsReady() { Locale locale = Locale.getDefault(); int languageAvailability = tts.isLanguageAvailable(locale); if (languageAvailability == TextToSpeech.LANG_MISSING_DATA || languageAvailability == TextToSpeech.LANG_NOT_SUPPORTED) { Log.w(TAG, "Default locale not available, use English."); locale = Locale.ENGLISH; /* * TODO: instead of using english, load the language if missing and show a * toast if not supported. Not able to change the resource strings to * English. */ } tts.setLanguage(locale); // Slow down the speed just a bit as it is hard to hear when exercising. tts.setSpeechRate(TTS_SPEECH_RATE); }
/** Initializing of the TTS engine. */ public void onInit(int status) { // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. if (status == TextToSpeech.SUCCESS) { // Set preferred language to US english. // Note that a language may not be available, and the result will indicate this. int result = mTts.setLanguage(Locale.US); // Try this someday for some interesting results. if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { // Language data is missing or the language is not supported. if (mRobotType == R.id.robot_type_lejos) showToast(R.string.tts_language_not_supported, Toast.LENGTH_LONG); } } else { // Initialization failed. if (mRobotType == R.id.robot_type_lejos) showToast(R.string.tts_initialization_failure, Toast.LENGTH_LONG); } }
public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { // aqui decidimos qual a lingua padrão da fala, esquecam não tem portugues int result = tts.setLanguage(Locale.US); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "Esta Lingua não é suportada"); } else { btnSpeak.setEnabled(true); speakOut(); } } else { Log.e("TTS", "Erro na Inicialização"); } }
public static void speak(String text, String loc) { int result = mTts.setLanguage(new Locale(loc)); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Toast.makeText( mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message) + " (" + loc + ")", Toast.LENGTH_LONG) .show(); Timber.e("Error loading locale " + loc); } else { if (mTts.isSpeaking()) { Timber.d("tts engine appears to be busy... clearing queue"); stopTts(); // sTextQueue.add(new String[] { text, loc }); } Timber.d("tts text '%s' to be played for locale (%s)", text, loc); mTts.speak(mTextToSpeak, TextToSpeech.QUEUE_FLUSH, mTtsParams); } }
/** * Attempt to start speaking an utterance. If it returns true, will call back on start and end. * * @param utteranceId A unique id for this utterance so that callbacks can be tied to a particular * utterance. * @param text The text to speak. * @param lang The language code for the text (e.g., "en-US"). * @param rate The speech rate, in the units expected by Android TextToSpeech. * @param pitch The speech pitch, in the units expected by Android TextToSpeech. * @param volume The speech volume, in the units expected by Android TextToSpeech. * @return true on success. */ @CalledByNative private boolean speak( int utteranceId, String text, String lang, float rate, float pitch, float volume) { assert mInitialized == true; if (!lang.equals(mCurrentLanguage)) { mTextToSpeech.setLanguage(new Locale(lang)); mCurrentLanguage = lang; } mTextToSpeech.setSpeechRate(rate); mTextToSpeech.setPitch(pitch); HashMap<String, String> params = new HashMap<String, String>(); if (volume != 1.0) { params.put(TextToSpeech.Engine.KEY_PARAM_VOLUME, Double.toString(volume)); } params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, Integer.toString(utteranceId)); int result = mTextToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, params); return (result == TextToSpeech.SUCCESS); }
@Override public void onInit(int status) { // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. if (status == TextToSpeech.SUCCESS) { // Set preferred language to US english. // Note that a language may not be available, and the result will // indicate this. int result = mTts.setLanguage(Locale.US); // Try this someday for some interesting results. // int result mTts.setLanguage(Locale.FRANCE); 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 { // Initialization failed. Log.e(TAG, "Could not initialize TextToSpeech."); } }
@Override public void onInit(int status) { // TODO Auto-generated method stub if (status == TextToSpeech.SUCCESS) { int result = textTalker.setLanguage(Locale.US); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Toast.makeText(this, "Language not supported", Toast.LENGTH_LONG).show(); } else { } } else { Log.e("TTS", "Initilization Failed"); } textTalker.speak(yy, TextToSpeech.QUEUE_FLUSH, null); t.setText(yy); }
@Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { if (tts == null) { tts = new TextToSpeech(this, this); tts.setSpeechRate(0.8f); } int result = tts.setLanguage(Locale.ENGLISH); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "This Language is not supported"); Intent installIntent = new Intent(); installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); } speakIt("You are in the impressionist exhibit"); } }
public void onInit(int status) { try { if (initLock.tryLock() || initLock.tryLock(INIT_LOCK_TIMEOUT, TimeUnit.SECONDS)) { initLock.unlock(); } else { Log.e(TAG, "TTS init timed out"); return; } } catch (InterruptedException e) { Log.e(TAG, "TTS init lock waiting is interrupted."); } if (status == TextToSpeech.SUCCESS) { Log.v(TAG, "init!" + myLocale.toString()); assert myTTS != null; assert myLocale != null; int result = myTTS.setLanguage(myLocale); if (result == TextToSpeech.LANG_MISSING_DATA) { Toast.makeText( context, context.getString(R.string.tts_language_data_missing_text) + " " + myLocale, Toast.LENGTH_LONG) .show(); Log.e(TAG, "Missing language data"); } if (result == TextToSpeech.LANG_NOT_SUPPORTED) { Toast.makeText( context, context.getString(R.string.unsupported_audio_locale_text) + " " + myLocale, Toast.LENGTH_LONG) .show(); Log.e(TAG, "Language is not supported"); } } else { Log.e(TAG, "Can't initialize"); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.counter_activity); tvCounter = (TextView) findViewById(R.id.tvCounter); cflCounter = (CounterFrameLayout) findViewById(R.id.cflCounter); tvCounter.setText("" + mRepCounter); mHub = Hub.getInstance(); if (!mHub.init(this, getPackageName())) { // We can't do anything with the Myo device if the Hub can't be initialized, so exit. Toast.makeText(this, "Couldn't initialize Hub", Toast.LENGTH_SHORT).show(); finish(); return; } mTextToSpeech = new TextToSpeech( getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int status) {} }); mTextToSpeech.setLanguage(Locale.US); Intent intent = getIntent(); mWorkout = intent.getParcelableExtra(Workout.TAG); mHub.setLockingPolicy(Hub.LockingPolicy.NONE); mHub.addListener(mWorkout); float peak = intent.getFloatExtra(CalibrationActivity.KEY_PEAK, 0); float dip = intent.getFloatExtra(CalibrationActivity.KEY_DIP, 0); mWorkout.setRange(dip, peak); mWorkout.setCallback(this); Log.e(TAG, "PEAK: " + dip); Log.e(TAG, "DIP: " + peak); }
public void textToSpeechTeller(String spokenText) { textToSpeech = new TextToSpeech(context, this); textToSpeech.setLanguage(Locale.US); textToSpeech.setPitch((float) 2); if (spokenText.toLowerCase().contains("how ") || spokenText.toLowerCase().contains(" how ") || spokenText.toLowerCase().equals("how") || spokenText.toLowerCase().equals("how's")) { voiceResponse = howResponses[random.nextInt((howResponses.length))]; } else if (spokenText.toLowerCase().contains("who ") || spokenText.toLowerCase().contains(" who ") || spokenText.toLowerCase().equals("who") || spokenText.toLowerCase().equals("who's")) { voiceResponse = whoResponses[random.nextInt((whoResponses.length))]; } else if (spokenText.toLowerCase().contains("when ") || spokenText.toLowerCase().contains(" when ") || spokenText.toLowerCase().equals("when")) { voiceResponse = whenResponses[random.nextInt((whenResponses.length))]; } else if (spokenText.toLowerCase().contains("what ") || spokenText.toLowerCase().contains(" what ") || spokenText.toLowerCase().equals("what") || spokenText.toLowerCase().equals("what's")) { voiceResponse = whatResponses[random.nextInt((whatResponses.length))]; } else if (spokenText.toLowerCase().contains("where ") || spokenText.toLowerCase().contains(" where ") || spokenText.toLowerCase().equals("where") || spokenText.toLowerCase().equals("where's")) { voiceResponse = whereResponses[random.nextInt((whereResponses.length))]; } else if (spokenText.toLowerCase().equals("am") || spokenText.toLowerCase().equals("will") || spokenText.toLowerCase().contains("am ") || spokenText.toLowerCase().contains("will ") || spokenText.toLowerCase().contains(" am ") || spokenText.toLowerCase().contains(" will ")) { voiceResponse = amAndWillResponses[random.nextInt((amAndWillResponses.length))]; } else voiceResponse = "Ask me a real question"; }
// implement on Init for the text to speech public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { // Set preferred language to US english. // Note that a language may not be available, and the result will // indicate this. int result = mTts.setLanguage(Locale.US); // Try this someday for some interesting results. // int result mTts.setLanguage(Locale.FRANCE); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { // Language data is missing or the language is not supported. Log.e(TAG, "Language is not available."); } else { // mSpeakButton.setEnabled(true); // mPauseButton.setEnabled(true); // Greet the user. // sayHello(); } } else { // Initialization failed. Log.e(TAG, "Could not initialize TextToSpeech."); } }
private static void setLanguageTts(Locale languageShortName) { if (myTts != null) { myTts.setLanguage(languageShortName); } }