diff options
| author | Android (Google) Code Review <android-gerrit@google.com> | 2009-10-26 20:53:45 -0400 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-10-26 20:53:45 -0400 |
| commit | 8212a841f60caa874e666d1bf4482bec6f5dd902 (patch) | |
| tree | 5c7c6c1c08643737dbc0f5b36fe244f91e5d364c | |
| parent | a413314001d45af4b5a3a0a2d1a130ef21bf0b23 (diff) | |
| parent | 998207c82190dc941fa702b15642f5f698bed21c (diff) | |
| download | frameworks_base-8212a841f60caa874e666d1bf4482bec6f5dd902.zip frameworks_base-8212a841f60caa874e666d1bf4482bec6f5dd902.tar.gz frameworks_base-8212a841f60caa874e666d1bf4482bec6f5dd902.tar.bz2 | |
Merge change I824f0fc9
* changes:
Adding support for plugins.
| -rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index 217d3bb..c816a21 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -20,8 +20,10 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; @@ -39,6 +41,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.TimeUnit; @@ -146,6 +149,8 @@ public class TtsService extends Service implements OnCompletionListener { private final ReentrantLock synthesizerLock = new ReentrantLock(); private static SynthProxy sNativeSynth = null; + private String currentSpeechEngineSOFile = ""; + @Override public void onCreate() { super.onCreate(); @@ -153,6 +158,9 @@ public class TtsService extends Service implements OnCompletionListener { mResolver = getContentResolver(); + currentSpeechEngineSOFile = ""; + setEngine(getDefaultEngine()); + String soLibPath = "/system/lib/libttspico.so"; if (sNativeSynth == null) { sNativeSynth = new SynthProxy(soLibPath); @@ -194,6 +202,54 @@ public class TtsService extends Service implements OnCompletionListener { } + private int setEngine(String enginePackageName) { + String soFilename = ""; + // The SVOX TTS is an exception to how the TTS packaging scheme works + // because it is part of the system and not a 3rd party add-on; thus + // its binary is actually located under /system/lib/ + if (enginePackageName.equals("com.svox.pico")) { + soFilename = "/system/lib/libttspico.so"; + } else { + // Find the package + Intent intent = new Intent("android.intent.action.START_TTS_ENGINE"); + intent.setPackage(enginePackageName); + ResolveInfo[] enginesArray = new ResolveInfo[0]; + PackageManager pm = getPackageManager(); + List <ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0); + if ((resolveInfos == null) || resolveInfos.isEmpty()) { + Log.e(SERVICE_TAG, "Invalid TTS Engine Package: " + enginePackageName); + return TextToSpeech.ERROR; + } + enginesArray = resolveInfos.toArray(enginesArray); + // Generate the TTS .so filename from the package + ActivityInfo aInfo = enginesArray[0].activityInfo; + soFilename = aInfo.name.replace(aInfo.packageName + ".", "") + ".so"; + soFilename = soFilename.toLowerCase(); + soFilename = "/data/data/" + aInfo.packageName + "/lib/libtts" + soFilename; + } + + if (currentSpeechEngineSOFile.equals(soFilename)) { + return TextToSpeech.SUCCESS; + } + + File f = new File(soFilename); + if (!f.exists()) { + Log.e(SERVICE_TAG, "Invalid TTS Binary: " + soFilename); + return TextToSpeech.ERROR; + } + + if (sNativeSynth != null) { + sNativeSynth.stopSync(); + sNativeSynth.shutdown(); + sNativeSynth = null; + } + sNativeSynth = new SynthProxy(soFilename); + currentSpeechEngineSOFile = soFilename; + return TextToSpeech.SUCCESS; + } + + + private void setDefaultSettings() { setLanguage("", this.getDefaultLanguage(), getDefaultCountry(), getDefaultLocVariant()); @@ -209,6 +265,15 @@ public class TtsService extends Service implements OnCompletionListener { == 1 ); } + private String getDefaultEngine() { + String defaultEngine = android.provider.Settings.Secure.getString(mResolver, + android.provider.Settings.Secure.TTS_DEFAULT_SYNTH); + if (defaultEngine == null) { + return TextToSpeech.Engine.DEFAULT_SYNTH; + } else { + return defaultEngine; + } + } private int getDefaultRate() { return android.provider.Settings.Secure.getInt(mResolver, |
