Created
May 20, 2014 15:47
-
-
Save brandall76/eb30bce199921a2944c9 to your computer and use it in GitHub Desktop.
Analyse & Store TTS information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Container Class | |
public class ContainerVoiceEngine { | |
private String label; | |
private String packageName; | |
private ArrayList<String> voices; | |
private Intent intent; | |
public ContainerVoiceEngine() { | |
} | |
public ContainerVoiceEngine(final String label, final String packageName, final ArrayList<String> voices, final Intent intent) { | |
this.label = label; | |
this.packageName = packageName; | |
this.voices = voices; | |
this.intent = intent; | |
} | |
public Intent getIntent() { | |
return intent; | |
} | |
public void setIntent(final Intent intent) { | |
this.intent = intent; | |
} | |
public String getLabel() { | |
return label; | |
} | |
public void setLabel(final String label) { | |
this.label = label; | |
} | |
public String getPackageName() { | |
return packageName; | |
} | |
public void setPackageName(final String packageName) { | |
this.packageName = packageName; | |
} | |
public ArrayList<String> getVoices() { | |
return voices; | |
} | |
public void setVoices(final ArrayList<String> voices) { | |
this.voices = voices; | |
} | |
} | |
// Usage within an Activity - Debugging only! | |
private ArrayList<ContainerVoiceEngine> containerVEArray; | |
private int requestCount; | |
private void getEngines() { | |
requestCount = 0; | |
final Intent ttsIntent = new Intent(); | |
ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); | |
final PackageManager pm = getPackageManager(); | |
final List<ResolveInfo> list = pm.queryIntentActivities(ttsIntent, PackageManager.GET_META_DATA); | |
containerVEArray = new ArrayList<ContainerVoiceEngine>(list.size()); | |
for (int i = 0; i < list.size(); i++) { | |
final ContainerVoiceEngine cve = new ContainerVoiceEngine(); | |
cve.setLabel(list.get(i).loadLabel(pm).toString()); | |
cve.setPackageName(list.get(i).activityInfo.applicationInfo.packageName); | |
final Intent getIntent = new Intent(); | |
getIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); | |
getIntent.setPackage(cve.getPackageName()); | |
getIntent.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES); | |
getIntent.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES); | |
cve.setIntent(getIntent); | |
containerVEArray.add(cve); | |
} | |
Log.d("TAG", "containerVEArray: " + containerVEArray.size()); | |
for (int i = 0; i < containerVEArray.size(); i++) { | |
startActivityForResult(containerVEArray.get(i).getIntent(), i); | |
} | |
} | |
@Override | |
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { | |
Log.i("TAG", "onActivityResult: requestCount: " + " - requestCode: " + requestCode); | |
requestCount++; | |
try { | |
if (data != null) { | |
final Bundle bundle = data.getExtras(); | |
if (bundle != null) { | |
Log.d("TAG", containerVEArray.get(requestCode).getLabel() + " - Bundle Data"); | |
final Set<String> keys = bundle.keySet(); | |
final Iterator<String> it = keys.iterator(); | |
while (it.hasNext()) { | |
final String key = it.next(); | |
Log.d("TAG", "Key: " + key + " = " + bundle.get(key)); | |
} | |
} | |
if (data.hasExtra("availableVoices")) { | |
containerVEArray.get(requestCode).setVoices(data.getStringArrayListExtra("availableVoices")); | |
} else { | |
containerVEArray.get(requestCode).setVoices(new ArrayList<String>()); | |
} | |
} | |
if (requestCount == containerVEArray.size()) { | |
for (int i = 0; i < containerVEArray.size(); i++) { | |
Log.v("TAG", "cve: " + containerVEArray.get(i).getLabel() + " - " | |
+ containerVEArray.get(i).getVoices().size() + " - " + containerVEArray.get(i).getVoices().toString()); | |
} | |
} | |
} catch (final IndexOutOfBoundsException e) { | |
Log.e("TAG", "IndexOutOfBoundsException"); | |
e.printStackTrace(); | |
} catch (final NullPointerException e) { | |
Log.e("TAG", "NullPointerException"); | |
e.printStackTrace(); | |
} catch (final Exception e) { | |
Log.e("TAG", "Exception"); | |
e.printStackTrace(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment