use of android.speech.tts.TextToSpeech in project android_packages_apps_Settings by SudaMod.
the class TextToSpeechSettings method onResume.
@Override
public void onResume() {
super.onResume();
if (mTts == null || mCurrentDefaultLocale == null) {
return;
}
if (!mTts.getDefaultEngine().equals(mTts.getCurrentEngine())) {
try {
mTts.shutdown();
mTts = null;
} catch (Exception e) {
Log.e(TAG, "Error shutting down TTS engine" + e);
}
mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener);
setTtsUtteranceProgressListener();
initSettings();
} else {
// Do set pitch correctly after it may have changed, and unlike speed, it doesn't change
// immediately.
final ContentResolver resolver = getContentResolver();
mTts.setPitch(android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH) / 100.0f);
}
Locale ttsDefaultLocale = mTts.getDefaultLanguage();
if (mCurrentDefaultLocale != null && !mCurrentDefaultLocale.equals(ttsDefaultLocale)) {
updateWidgetState(false);
checkDefaultLocale();
}
}
use of android.speech.tts.TextToSpeech in project android_packages_apps_Settings by SudaMod.
the class TextToSpeechSettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.tts_settings);
getActivity().setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
mEnginesHelper = new TtsEngines(getActivity().getApplicationContext());
mLocalePreference = (ListPreference) findPreference(KEY_ENGINE_LOCALE);
mLocalePreference.setOnPreferenceChangeListener(this);
mDefaultPitchPref = (SeekBarPreference) findPreference(KEY_DEFAULT_PITCH);
mDefaultRatePref = (SeekBarPreference) findPreference(KEY_DEFAULT_RATE);
mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
mPlayButton = (Button) mActionButtons.findViewById(R.id.tts_play_button);
mPlayButton.setOnClickListener(this);
mPlayButton.setEnabled(false);
mResetButton = (Button) mActionButtons.findViewById(R.id.tts_reset_button);
mResetButton.setOnClickListener(this);
if (savedInstanceState == null) {
mLocalePreference.setEnabled(false);
mLocalePreference.setEntries(new CharSequence[0]);
mLocalePreference.setEntryValues(new CharSequence[0]);
} else {
// Repopulate mLocalePreference with saved state. Will be updated later with
// up-to-date values when checkTtsData() calls back with results.
final CharSequence[] entries = savedInstanceState.getCharSequenceArray(STATE_KEY_LOCALE_ENTRIES);
final CharSequence[] entryValues = savedInstanceState.getCharSequenceArray(STATE_KEY_LOCALE_ENTRY_VALUES);
final CharSequence value = savedInstanceState.getCharSequence(STATE_KEY_LOCALE_VALUE);
mLocalePreference.setEntries(entries);
mLocalePreference.setEntryValues(entryValues);
mLocalePreference.setValue(value != null ? value.toString() : null);
mLocalePreference.setEnabled(entries.length > 0);
}
mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener);
setTtsUtteranceProgressListener();
initSettings();
// Prevent restarting the TTS connection on rotation
setRetainInstance(true);
}
use of android.speech.tts.TextToSpeech in project android_packages_apps_Settings by SudaMod.
the class TtsEnginePreferenceFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.tts_engine_picker);
mEnginePreferenceCategory = (PreferenceCategory) findPreference("tts_engine_preference_category");
mEnginesHelper = new TtsEngines(getActivity().getApplicationContext());
mTts = new TextToSpeech(getActivity().getApplicationContext(), null);
initSettings();
}
use of android.speech.tts.TextToSpeech in project platform_packages_apps_Settings by BlissRoms.
the class TextToSpeechSettings method onResume.
@Override
public void onResume() {
super.onResume();
if (mTts == null || mCurrentDefaultLocale == null) {
return;
}
if (!mTts.getDefaultEngine().equals(mTts.getCurrentEngine())) {
try {
mTts.shutdown();
mTts = null;
} catch (Exception e) {
Log.e(TAG, "Error shutting down TTS engine" + e);
}
mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener);
setTtsUtteranceProgressListener();
initSettings();
} else {
// Do set pitch correctly after it may have changed, and unlike speed, it doesn't change
// immediately.
final ContentResolver resolver = getContentResolver();
mTts.setPitch(android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH) / 100.0f);
}
Locale ttsDefaultLocale = mTts.getDefaultLanguage();
if (mCurrentDefaultLocale != null && !mCurrentDefaultLocale.equals(ttsDefaultLocale)) {
updateWidgetState(false);
checkDefaultLocale();
}
}
use of android.speech.tts.TextToSpeech in project platform_packages_apps_Settings by BlissRoms.
the class TtsEnginePreferenceFragment method updateDefaultEngine.
private void updateDefaultEngine(String engine) {
Log.d(TAG, "Updating default synth to : " + engine);
// Keep track of the previous engine that was being used. So that
// we can reuse the previous engine.
//
// Note that if TextToSpeech#getCurrentEngine is not null, it means at
// the very least that we successfully bound to the engine service.
mPreviousEngine = mTts.getCurrentEngine();
// Step 1: Shut down the existing TTS engine.
Log.i(TAG, "Shutting down current tts engine");
if (mTts != null) {
try {
mTts.shutdown();
mTts = null;
} catch (Exception e) {
Log.e(TAG, "Error shutting down TTS engine" + e);
}
}
// Step 2: Connect to the new TTS engine.
// Step 3 is continued on #onUpdateEngine (below) which is called when
// the app binds successfully to the engine.
Log.i(TAG, "Updating engine : Attempting to connect to engine: " + engine);
mTts = new TextToSpeech(getActivity().getApplicationContext(), mUpdateListener, engine);
Log.i(TAG, "Success");
}
Aggregations