use of android.speech.tts.TextToSpeech in project android_frameworks_base by crdroidandroid.
the class TextToSpeechTests method blockingInitAndVerify.
private void blockingInitAndVerify(final String engine, int errorCode) throws InterruptedException {
TextToSpeech.OnInitListener listener = LittleMock.mock(TextToSpeech.OnInitListener.class);
final CountDownLatch latch = new CountDownLatch(1);
doCountDown(latch).when(listener).onInit(errorCode);
mTts = new TextToSpeech(getInstrumentation().getTargetContext(), listener, engine, MOCK_PACKAGE, false);
awaitCountDown(latch, 5, TimeUnit.SECONDS);
}
use of android.speech.tts.TextToSpeech in project android_packages_apps_Settings by LineageOS.
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 LineageOS.
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 LineageOS.
the class TtsEnginePreferenceFragment method onUpdateEngine.
/**
* Step 3: We have now bound to the TTS engine the user requested. We will attempt to check
* voice data for the engine if we successfully bound to it, or revert to the previous engine if
* we didn't.
*/
public void onUpdateEngine(int status) {
if (status == TextToSpeech.SUCCESS) {
Log.d(TAG, "Updating engine: Successfully bound to the engine: " + mTts.getCurrentEngine());
android.provider.Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, mTts.getCurrentEngine());
} else {
Log.d(TAG, "Updating engine: Failed to bind to engine, reverting.");
if (mPreviousEngine != null) {
// This is guaranteed to at least bind, since mPreviousEngine would be
// null if the previous bind to this engine failed.
mTts = new TextToSpeech(getActivity().getApplicationContext(), null, mPreviousEngine);
}
mPreviousEngine = null;
}
}
use of android.speech.tts.TextToSpeech in project instructure-android by instructure.
the class StudentChooserFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (getArguments() != null) {
Course course = getArguments().getParcelable(Const.COURSE);
courseName.setText(course.getName());
sectionPeople = getArguments().getParcelableArrayList(Const.SECTION_PEOPLE);
for (User user : sectionPeople) {
adapter.addItem(user);
}
if (adapter.getCount() == 0) {
showEmptyView();
emptyView.setText(getString(R.string.noStudents));
}
getParentActivity().setActionBarTitle(getString(R.string.studentChooser));
}
getCheckedState();
// initialize the text to speech engine
tts = new TextToSpeech(getActivity(), 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) {
Log.e("error", "This Language is not supported");
} else {
tts.setLanguage(Locale.getDefault());
}
} else {
Log.e("error", "Initilization Failed!");
}
}
});
}
Aggregations