问题
I've been running through many of the text to speech examples available for Android and I have an issue that I assume is really simple, but I cannot for the life of me work it out!
I simply want to be able to view the output of EXTRA_AVAILABLE_VOICES (for example) which according to this link is returned in an ArrayList. There are many examples of how to deal with such output programmatically, but for the benefit of my learning and understanding, I want to see the actual returned data for myself.
My project is set up exactly as the android developers example from here
// We now return the list of available and unavailable voices
// as well as the return code.
Intent returnData = new Intent();
returnData.putStringArrayListExtra(
TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES, available);
returnData.putStringArrayListExtra(
TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES, unavailable);
setResult(result, returnData);
finish();
}
Ideally I'd like to have the output displayed after the 'constant value' in a simple TextView from a string, but I can't achieve that, neither can I get it in a ListView despite my many efforts... Please can someone help me solve this!
Once I know how to view the returned data, I can then go on to follow the examples of how to deal with it correctly.
- I've not included any the code I've already tried, as I can't find an example anywhere and it's been pure guess work (which I be embarrassed to show!)
Thanks in advance.
回答1:
For anyone who is ever stuck with the same thing, I used the code below, edited from the sample found here:
ArrayList<String> available = data
.getStringArrayListExtra("availableVoices");
Log.v("languages count", String.valueOf(available.size()));
Iterator<String> iter = available.iterator();
while (iter.hasNext()) {
String lang = iter.next();
Locale locale = new Locale(lang);
Log.v(TAG, "language: " + lang);
Log.v(TAG, "language locale: " + locale.toString());
TextView LocaleResults = (TextView) getView().findViewById(
R.id.textViewConfig);
LocaleResults.append("\nAvailable Engine Language: " + lang);
}
ArrayList<String> unavailable = data
.getStringArrayListExtra("unavailableVoices");
Log.v("languages count", String.valueOf(unavailable.size()));
Iterator<String> iteru = unavailable.iterator();
while (iteru.hasNext()) {
String ulang = iteru.next();
Locale ulocale = new Locale(ulang);
Log.v(TAG, "ulanguage: " + ulang);
Log.v(TAG, "ulanguage locale: " + ulocale.toString());
TextView LocaleResults = (TextView) getView().findViewById(
R.id.textViewConfig);
LocaleResults.append("\nUnavailable Engine Language: " + ulang);
}
来源:https://stackoverflow.com/questions/9612997/android-java-text-to-speech-viewing-extra-string-information