Adding the ability to specify the speech synthesis
engine to use for text-to-speech.
diff --git a/api/current.xml b/api/current.xml
index db6bfb7..eb52977 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -124607,6 +124607,19 @@
<parameter name="params" type="java.util.HashMap<java.lang.String, java.lang.String>">
</parameter>
</method>
+<method name="setEngineByPackageName"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="enginePackageName" type="java.lang.String">
+</parameter>
+</method>
<method name="setLanguage"
return="int"
abstract="false"
diff --git a/core/java/android/speech/tts/ITts.aidl b/core/java/android/speech/tts/ITts.aidl
index 1812188..2ed660a 100755
--- a/core/java/android/speech/tts/ITts.aidl
+++ b/core/java/android/speech/tts/ITts.aidl
@@ -59,5 +59,7 @@
int unregisterCallback(in String callingApp, ITtsCallback cb);
- int playSilence(in String callingApp, in long duration, in int queueMode, in String[] params);
+ int playSilence(in String callingApp, in long duration, in int queueMode, in String[] params);
+
+ int setEngineByPackageName(in String enginePackageName);
}
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index 3f369dd..bd19f9e 100755
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -1254,4 +1254,44 @@
}
}
+ /**
+ * Sets the speech synthesis engine to be used by its packagename.
+ *
+ * @param enginePackageName
+ * The packagename for the synthesis engine (ie, "com.svox.pico")
+ *
+ * @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}.
+ */
+ public int setEngineByPackageName(String enginePackageName) {
+ synchronized (mStartLock) {
+ int result = TextToSpeech.ERROR;
+ if (!mStarted) {
+ return result;
+ }
+ try {
+ result = mITts.setEngineByPackageName(enginePackageName);
+ } catch (RemoteException e) {
+ // TTS died; restart it.
+ Log.e("TextToSpeech.java - setEngineByPackageName", "RemoteException");
+ e.printStackTrace();
+ mStarted = false;
+ initTts();
+ } catch (NullPointerException e) {
+ // TTS died; restart it.
+ Log.e("TextToSpeech.java - setEngineByPackageName", "NullPointerException");
+ e.printStackTrace();
+ mStarted = false;
+ initTts();
+ } catch (IllegalStateException e) {
+ // TTS died; restart it.
+ Log.e("TextToSpeech.java - setEngineByPackageName", "IllegalStateException");
+ e.printStackTrace();
+ mStarted = false;
+ initTts();
+ } finally {
+ return result;
+ }
+ }
+ }
+
}
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java
index c816a21..8d8ef8e 100755
--- a/packages/TtsService/src/android/tts/TtsService.java
+++ b/packages/TtsService/src/android/tts/TtsService.java
@@ -1326,6 +1326,17 @@
return mSelf.synthesizeToFile(callingApp, text, speakingParams, filename);
}
+ /**
+ * Sets the speech synthesis engine for the TTS by specifying its packagename
+ *
+ * @param packageName the packageName of the speech synthesis engine (ie, "com.svox.pico")
+ *
+ * @return SUCCESS or ERROR as defined in android.speech.tts.TextToSpeech.
+ */
+ public int setEngineByPackageName(String packageName) {
+ return mSelf.setEngine(packageName);
+ }
+
};
}