I would like to know programmatically how to get TTS engine info of the device for e.g. whether any TTS engine is installed or not , if installed then what are those and wha
This official Android Blog Post gives you the best practice to detect if the TTS Engine is installed and ready to use, as well as other practices on TTS.
To save your clicks:
Launch this to check if TTS is installed or not:
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
and then get result in this:
private TextToSpeech mTts;
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
You can check it by first sending an intent for result
Intent intent = new Intent();
intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(intent, 0);
Then you can check it that if you have installed TTS engine or not in onActivityResult method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0){
if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
Toast.makeText(getApplicationContext(),"Already Installed", Toast.LENGTH_LONG).show();
} else {
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
Toast.makeText(getApplicationContext(),"Installed Now", Toast.LENGTH_LONG).show();
}
Hope it works :)
This gives you the list of TTS Engines installed on your Android.
tts = new TextToSpeech(this, this);
for (TextToSpeech.EngineInfo engines : tts.getEngines()) {
Log.d("Engine Info " , engines.toString());
}