use of android.speech.tts.TextToSpeech.EngineInfo in project LibreraReader by foobnix.
the class DragingDialogs method textToSpeachDialog.
public static void textToSpeachDialog(final FrameLayout anchor, final DocumentController controller, final String textToRead) {
if (TTSEngine.get().hasNoEngines()) {
Urls.openTTS(controller.getActivity());
return;
}
DragingPopup dialog = new DragingPopup(R.string.text_to_speech, anchor, 300, 440) {
@Override
@SuppressLint("NewApi")
public View getContentView(LayoutInflater inflater) {
final Activity activity = controller.getActivity();
final View view = inflater.inflate(R.layout.dialog_tts, null, false);
final TextView ttsPage = (TextView) view.findViewById(R.id.ttsPage);
// ttsPage.setText(activity.getString(R.string.page) + " " +
// controller.getCurentPageFirst1());
final TextView textEngine = (TextView) view.findViewById(R.id.ttsEngine);
final TextView textDebug = (TextView) view.findViewById(R.id.textDebug);
final TextView timerTime = (TextView) view.findViewById(R.id.timerTime);
final TextView timerStart = (TextView) view.findViewById(R.id.timerStart);
timerTime.setText(AppState.get().ttsTimer + " " + controller.getString(R.string.minutes).toLowerCase(Locale.US));
timerTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (int i = 15; i <= 300; i += 15) {
final int number = i;
popupMenu.getMenu().add("" + i).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().ttsTimer = number;
timerTime.setText(AppState.get().ttsTimer + " " + controller.getString(R.string.minutes).toLowerCase(Locale.US));
return false;
}
});
}
popupMenu.show();
}
});
timerStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (TempHolder.get().timerFinishTime == 0) {
TempHolder.get().timerFinishTime = System.currentTimeMillis() + AppState.get().ttsTimer * 60 * 1000;
} else {
TempHolder.get().timerFinishTime = 0;
}
timerStart.setText(TempHolder.get().timerFinishTime == 0 ? R.string.start : R.string.cancel);
ttsPage.setText(TempHolder.get().timerFinishTime == 0 ? "" : controller.getString(R.string.reading_will_be_stopped) + " " + DateFormat.getTimeFormat(activity).format(TempHolder.get().timerFinishTime));
}
});
timerStart.setText(TempHolder.get().timerFinishTime == 0 ? R.string.start : R.string.cancel);
ttsPage.setText(TempHolder.get().timerFinishTime == 0 ? "" : controller.getString(R.string.reading_will_be_stopped) + " " + DateFormat.getTimeFormat(activity).format(TempHolder.get().timerFinishTime));
TTSEngine.get().getTTS(new OnInitListener() {
@Override
public void onInit(int status) {
textEngine.setText(TTSEngine.get().getCurrentEngineName());
TxtUtils.underlineTextView(textEngine);
}
});
textEngine.setText(TTSEngine.get().getCurrentEngineName());
TxtUtils.underlineTextView(textEngine);
textEngine.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu menu = new PopupMenu(v.getContext(), v);
List<EngineInfo> engines = TTSEngine.get().getTTS().getEngines();
for (final EngineInfo eInfo : engines) {
final String name = TTSEngine.engineToString(eInfo);
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
textEngine.setText(name);
TTSEngine.get().setTTSWithEngine(eInfo.name);
TxtUtils.underlineTextView(textEngine);
return false;
}
});
}
menu.show();
}
});
view.findViewById(R.id.ttsSettings).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
TTSEngine.get().stop();
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 14) {
intent.setAction("com.android.settings.TTS_SETTINGS");
} else {
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.TextToSpeechSettings"));
}
activity.startActivity(intent);
} catch (Exception e) {
Toast.makeText(activity, e.getMessage(), Toast.LENGTH_LONG).show();
LOG.e(e);
}
}
});
view.findViewById(R.id.onPlay).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TTSService.playBookPage(controller.getCurentPageFirst1() - 1, controller.getCurrentBook().getPath(), "", controller.getBookWidth(), controller.getBookHeight(), AppState.get().fontSizeSp);
}
});
view.findViewById(R.id.onPause).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TTSEngine.get().stop();
TTSNotification.hideNotification();
}
});
view.findViewById(R.id.onPause).setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
textDebug.setVisibility(View.VISIBLE);
return true;
}
});
final SeekBar seekBarSpeed = (SeekBar) view.findViewById(R.id.seekBarSpeed);
seekBarSpeed.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
AppState.get().ttsSpeed = (float) progress / 100;
}
}
});
final SeekBar seekBarPitch = (SeekBar) view.findViewById(R.id.seekBarPitch);
seekBarPitch.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
AppState.get().ttsPitch = (float) progress / 100;
}
}
});
seekBarPitch.setProgress((int) (AppState.get().ttsPitch * 100));
seekBarSpeed.setProgress((int) (AppState.get().ttsSpeed * 100));
final AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
final SeekBar seekVolume = (SeekBar) view.findViewById(R.id.seekVolume);
seekVolume.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
seekVolume.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
seekVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
}
}
});
TxtUtils.underlineTextView((TextView) view.findViewById(R.id.restore_defaults)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog(controller.getActivity(), controller.getString(R.string.restore_defaults_full), new Runnable() {
@Override
public void run() {
seekBarPitch.setProgress(100);
seekBarSpeed.setProgress(100);
AppState.get().ttsPitch = (float) 1.0;
AppState.get().ttsSpeed = (float) 1.0;
TTSEngine.get().shutdown();
TTSEngine.get().getTTS();
textEngine.setText(TTSEngine.get().getCurrentEngineName());
TxtUtils.underlineTextView(textEngine);
}
});
}
});
//
CheckBox notificationOngoing = (CheckBox) view.findViewById(R.id.notificationOngoing);
notificationOngoing.setChecked(AppState.get().notificationOngoing);
notificationOngoing.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().notificationOngoing = isChecked;
TTSNotification.hideNotification();
TTSNotification.showLast();
}
});
CheckBox stopReadingOnCall = (CheckBox) view.findViewById(R.id.stopReadingOnCall);
stopReadingOnCall.setChecked(AppState.get().stopReadingOnCall);
stopReadingOnCall.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().stopReadingOnCall = isChecked;
}
});
view.findViewById(R.id.ttsSkeakToFile).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder dialog = new AlertDialog.Builder(controller.getActivity());
dialog.setTitle(R.string.speak_into_file_wav_);
View inflate = LayoutInflater.from(v.getContext()).inflate(R.layout.dialog_tts_wav, null, false);
final TextView ttsSpeakPath = (TextView) inflate.findViewById(R.id.ttsSpeakPath);
final TextView progressText = (TextView) inflate.findViewById(R.id.progressText);
final ProgressBar progressBar1 = (ProgressBar) inflate.findViewById(R.id.progressBar1);
final Button start = (Button) inflate.findViewById(R.id.start);
final Button stop = (Button) inflate.findViewById(R.id.stop);
progressBar1.setVisibility(View.GONE);
progressText.setText("");
ttsSpeakPath.setText(Html.fromHtml("<u>" + AppState.get().ttsSpeakPath + "/<b>" + controller.getCurrentBook().getName() + "</b></u>"));
ttsSpeakPath.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ChooserDialogFragment.chooseFolder((FragmentActivity) controller.getActivity(), AppState.get().ttsSpeakPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
AppState.get().ttsSpeakPath = nPath;
ttsSpeakPath.setText(Html.fromHtml("<u>" + AppState.get().ttsSpeakPath + "/<b>" + controller.getCurrentBook().getName() + "</b></u>"));
dialog.dismiss();
return false;
}
});
}
});
final ResultResponse<String> info = new ResultResponse<String>() {
@Override
public boolean onResultRecive(final String result) {
controller.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
progressText.setText(result);
}
});
return false;
}
};
stop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TempHolder.isRecordTTS = false;
progressBar1.setVisibility(View.GONE);
}
});
start.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!TempHolder.isRecordTTS) {
TempHolder.isRecordTTS = true;
progressBar1.setVisibility(View.VISIBLE);
TTSEngine.get().speakToFile(controller, info);
}
}
});
dialog.setView(inflate);
dialog.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TempHolder.isRecordTTS = false;
}
});
AlertDialog create = dialog.create();
create.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
TempHolder.isRecordTTS = false;
}
});
create.show();
}
});
return view;
}
};
dialog.setOnCloseListener(new Runnable() {
@Override
public void run() {
AppState.get().save(controller.getActivity());
}
});
dialog.show("TTS");
}
use of android.speech.tts.TextToSpeech.EngineInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class TtsEnginePreferenceFragment method initSettings.
private void initSettings() {
if (mTts != null) {
mCurrentEngine = mTts.getCurrentEngine();
}
mEnginePreferenceCategory.removeAll();
List<EngineInfo> engines = mEnginesHelper.getEngines();
for (EngineInfo engine : engines) {
TtsEnginePreference enginePref = new TtsEnginePreference(getPrefContext(), engine, this);
mEnginePreferenceCategory.addPreference(enginePref);
}
}
use of android.speech.tts.TextToSpeech.EngineInfo in project android_frameworks_base by ParanoidAndroid.
the class TtsEngines method getEngines.
/**
* Gets a list of all installed TTS engines.
*
* @return A list of engine info objects. The list can be empty, but never {@code null}.
*/
public List<EngineInfo> getEngines() {
PackageManager pm = mContext.getPackageManager();
Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
List<ResolveInfo> resolveInfos = pm.queryIntentServices(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfos == null)
return Collections.emptyList();
List<EngineInfo> engines = new ArrayList<EngineInfo>(resolveInfos.size());
for (ResolveInfo resolveInfo : resolveInfos) {
EngineInfo engine = getEngineInfo(resolveInfo, pm);
if (engine != null) {
engines.add(engine);
}
}
Collections.sort(engines, EngineInfoComparator.INSTANCE);
return engines;
}
use of android.speech.tts.TextToSpeech.EngineInfo in project android_frameworks_base by ParanoidAndroid.
the class TtsEngines method getEngineInfo.
private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
ServiceInfo service = resolve.serviceInfo;
if (service != null) {
EngineInfo engine = new EngineInfo();
// Using just the package name isn't great, since it disallows having
// multiple engines in the same package, but that's what the existing API does.
engine.name = service.packageName;
CharSequence label = service.loadLabel(pm);
engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
engine.icon = service.getIconResource();
engine.priority = resolve.priority;
engine.system = isSystemEngine(service);
return engine;
}
return null;
}
use of android.speech.tts.TextToSpeech.EngineInfo in project android_frameworks_base by AOSPA.
the class TtsEngines method getEngineInfo.
private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
ServiceInfo service = resolve.serviceInfo;
if (service != null) {
EngineInfo engine = new EngineInfo();
// Using just the package name isn't great, since it disallows having
// multiple engines in the same package, but that's what the existing API does.
engine.name = service.packageName;
CharSequence label = service.loadLabel(pm);
engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
engine.icon = service.getIconResource();
engine.priority = resolve.priority;
engine.system = isSystemEngine(service);
return engine;
}
return null;
}
Aggregations