am 1ea7a819: Merge "Fix crash with engines that don\'t override getVoices()." into mnc-dev
* commit '1ea7a819315ddaa104099229b2b32f75d08a50be': Fix crash with engines that don't override getVoices().
This commit is contained in:
@@ -1486,19 +1486,28 @@ public class TextToSpeech {
|
|||||||
// Get the default voice for the locale.
|
// Get the default voice for the locale.
|
||||||
String voiceName = service.getDefaultVoiceNameFor(language, country, variant);
|
String voiceName = service.getDefaultVoiceNameFor(language, country, variant);
|
||||||
if (TextUtils.isEmpty(voiceName)) {
|
if (TextUtils.isEmpty(voiceName)) {
|
||||||
Log.w(TAG, "Couldn't find the default voice for " + language + "/" +
|
Log.w(TAG, "Couldn't find the default voice for " + language + "-" +
|
||||||
country + "/" + variant);
|
country + "-" + variant);
|
||||||
return LANG_NOT_SUPPORTED;
|
return LANG_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load it.
|
// Load it.
|
||||||
if (service.loadVoice(getCallerIdentity(), voiceName) == TextToSpeech.ERROR) {
|
if (service.loadVoice(getCallerIdentity(), voiceName) == TextToSpeech.ERROR) {
|
||||||
|
Log.w(TAG, "The service claimed " + language + "-" + country + "-"
|
||||||
|
+ variant + " was available with voice name " + voiceName
|
||||||
|
+ " but loadVoice returned ERROR");
|
||||||
return LANG_NOT_SUPPORTED;
|
return LANG_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the language/country/variant of the voice, so #getLanguage will return
|
// Set the language/country/variant of the voice, so #getLanguage will return
|
||||||
// the currently set voice locale when called.
|
// the currently set voice locale when called.
|
||||||
Voice voice = getVoice(service, voiceName);
|
Voice voice = getVoice(service, voiceName);
|
||||||
|
if (voice == null) {
|
||||||
|
Log.w(TAG, "getDefaultVoiceNameFor returned " + voiceName + " for locale "
|
||||||
|
+ language + "-" + country + "-" + variant
|
||||||
|
+ " but getVoice returns null");
|
||||||
|
return LANG_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
String voiceLanguage = "";
|
String voiceLanguage = "";
|
||||||
try {
|
try {
|
||||||
voiceLanguage = voice.getLocale().getISO3Language();
|
voiceLanguage = voice.getLocale().getISO3Language();
|
||||||
@@ -1682,6 +1691,7 @@ public class TextToSpeech {
|
|||||||
private Voice getVoice(ITextToSpeechService service, String voiceName) throws RemoteException {
|
private Voice getVoice(ITextToSpeechService service, String voiceName) throws RemoteException {
|
||||||
List<Voice> voices = service.getVoices();
|
List<Voice> voices = service.getVoices();
|
||||||
if (voices == null) {
|
if (voices == null) {
|
||||||
|
Log.w(TAG, "getVoices returned null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Voice voice : voices) {
|
for (Voice voice : voices) {
|
||||||
@@ -1689,6 +1699,7 @@ public class TextToSpeech {
|
|||||||
return voice;
|
return voice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log.w(TAG, "Could not find voice " + voiceName + " in voice list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -293,7 +293,9 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
}
|
}
|
||||||
Set<String> features = onGetFeaturesForLanguage(locale.getISO3Language(),
|
Set<String> features = onGetFeaturesForLanguage(locale.getISO3Language(),
|
||||||
locale.getISO3Country(), locale.getVariant());
|
locale.getISO3Country(), locale.getVariant());
|
||||||
voices.add(new Voice(locale.toLanguageTag(), locale, Voice.QUALITY_NORMAL,
|
String voiceName = onGetDefaultVoiceNameFor(locale.getISO3Language(),
|
||||||
|
locale.getISO3Country(), locale.getVariant());
|
||||||
|
voices.add(new Voice(voiceName, locale, Voice.QUALITY_NORMAL,
|
||||||
Voice.LATENCY_NORMAL, false, features));
|
Voice.LATENCY_NORMAL, false, features));
|
||||||
}
|
}
|
||||||
return voices;
|
return voices;
|
||||||
|
|||||||
Reference in New Issue
Block a user