diff options
author | Narayan Kamath <narayan@google.com> | 2011-06-15 12:35:06 +0100 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2011-06-16 10:31:45 +0100 |
commit | c3edf2a01a2cf2123a3de17ec1da11a3b6c459f0 (patch) | |
tree | 24bc0e2676d252370a32b77b696c49b6aad25dee | |
parent | d7c8b6d2a4d2ec16f4f61c66f400d8b20726964c (diff) | |
download | frameworks_base-c3edf2a01a2cf2123a3de17ec1da11a3b6c459f0.zip frameworks_base-c3edf2a01a2cf2123a3de17ec1da11a3b6c459f0.tar.gz frameworks_base-c3edf2a01a2cf2123a3de17ec1da11a3b6c459f0.tar.bz2 |
Don't enforce defaults any more in the TextToSpeech API.
This has been discussed in an email thread. This brings the
text to speech API in line with other android APIs.
The user can set default speech rates / languages and
engine preferences, which the API obeys BUT these can be
overriden by individual apps (much like intent.setComponent
and intent.setClassName can be used to launch a specific
handler for a given intent).
Also, all installed engines are enabled by default. The
user is shown the "data privacy" warning every time an
installed engine is set to the default.
Change-Id: I24f5f331b3a7cc7ce1a62962192e3a452bdca9d4
-rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java | 11 | ||||
-rw-r--r-- | core/java/android/speech/tts/TextToSpeechService.java | 29 | ||||
-rw-r--r-- | core/java/android/speech/tts/TtsEngines.java | 51 |
3 files changed, 14 insertions, 77 deletions
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index 7d596df..40e9355 100755 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -498,8 +498,7 @@ public class TextToSpeech { private int initTts() { String defaultEngine = getDefaultEngine(); String engine = defaultEngine; - if (!areDefaultsEnforced() && !TextUtils.isEmpty(mRequestedEngine) - && mEnginesHelper.isEngineEnabled(mRequestedEngine)) { + if (mEnginesHelper.isEngineInstalled(mRequestedEngine)) { engine = mRequestedEngine; } @@ -1080,12 +1079,12 @@ public class TextToSpeech { } /** - * Checks whether the user's settings should override settings requested by the calling - * application. + * Checks whether the user's settings should override settings requested + * by the calling application. As of the Ice cream sandwich release, + * user settings never forcibly override the app's settings. */ public boolean areDefaultsEnforced() { - return Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.TTS_USE_DEFAULTS, Engine.USE_DEFAULTS) == 1; + return false; } /** diff --git a/core/java/android/speech/tts/TextToSpeechService.java b/core/java/android/speech/tts/TextToSpeechService.java index 3eea6b7..7ea9373 100644 --- a/core/java/android/speech/tts/TextToSpeechService.java +++ b/core/java/android/speech/tts/TextToSpeechService.java @@ -191,11 +191,6 @@ public abstract class TextToSpeechService extends Service { protected abstract void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback); - private boolean areDefaultsEnforced() { - return getSecureSettingInt(Settings.Secure.TTS_USE_DEFAULTS, - TextToSpeech.Engine.USE_DEFAULTS) == 1; - } - private int getDefaultSpeechRate() { return getSecureSettingInt(Settings.Secure.TTS_DEFAULT_RATE, Engine.DEFAULT_RATE); } @@ -504,13 +499,9 @@ public abstract class TextToSpeechService extends Service { } private void setRequestParams(SynthesisRequest request) { - if (areDefaultsEnforced()) { - request.setLanguage(getDefaultLanguage(), getDefaultCountry(), getDefaultVariant()); - request.setSpeechRate(getDefaultSpeechRate()); - } else { - request.setLanguage(getLanguage(), getCountry(), getVariant()); - request.setSpeechRate(getSpeechRate()); - } + request.setLanguage(getLanguage(), getCountry(), getVariant()); + request.setSpeechRate(getSpeechRate()); + request.setPitch(getPitch()); } @@ -749,13 +740,6 @@ public abstract class TextToSpeechService extends Service { return TextToSpeech.ERROR; } - if (areDefaultsEnforced()) { - if (isDefault(lang, country, variant)) { - return mDefaultAvailability; - } else { - return TextToSpeech.LANG_NOT_SUPPORTED; - } - } return onIsLanguageAvailable(lang, country, variant); } @@ -768,13 +752,6 @@ public abstract class TextToSpeechService extends Service { return TextToSpeech.ERROR; } - if (areDefaultsEnforced()) { - if (isDefault(lang, country, variant)) { - return mDefaultAvailability; - } else { - return TextToSpeech.LANG_NOT_SUPPORTED; - } - } return onLoadLanguage(lang, country, variant); } diff --git a/core/java/android/speech/tts/TtsEngines.java b/core/java/android/speech/tts/TtsEngines.java index 715894f..ed9e048 100644 --- a/core/java/android/speech/tts/TtsEngines.java +++ b/core/java/android/speech/tts/TtsEngines.java @@ -117,30 +117,10 @@ public class TtsEngines { return engines; } - /** - * Checks whether a given engine is enabled or not. Note that all system - * engines are enabled by default. - */ + // TODO: Used only by the settings app. Remove once + // the settings UI change has been finalized. public boolean isEngineEnabled(String engine) { - // System engines are enabled by default always. - EngineInfo info = getEngineInfo(engine); - if (info == null) { - // The engine is not installed, and therefore cannot - // be enabled. - return false; - } - - if (info.system) { - // All system engines are enabled by default. - return true; - } - - for (String enabled : getUserEnabledEngines()) { - if (engine.equals(enabled)) { - return true; - } - } - return false; + return isEngineInstalled(engine); } private boolean isSystemEngine(ServiceInfo info) { @@ -149,22 +129,14 @@ public class TtsEngines { } /** - * @return true if a given engine is installed on the system. Useful to deal - * with cases where an engine has been uninstalled by the user or removed - * for any other reason. + * @return true if a given engine is installed on the system. */ - private boolean isEngineInstalled(String engine) { + public boolean isEngineInstalled(String engine) { if (engine == null) { return false; } - for (EngineInfo info : getEngines()) { - if (engine.equals(info.name)) { - return true; - } - } - - return false; + return getEngineInfo(engine) != null; } private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) { @@ -185,17 +157,6 @@ public class TtsEngines { return null; } - // Note that in addition to this list, all engines that are a part - // of the system are enabled by default. - private String[] getUserEnabledEngines() { - String str = Settings.Secure.getString(mContext.getContentResolver(), - Settings.Secure.TTS_ENABLED_PLUGINS); - if (TextUtils.isEmpty(str)) { - return new String[0]; - } - return str.split(" "); - } - private static class EngineInfoComparator implements Comparator<EngineInfo> { private EngineInfoComparator() { } |