summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-07-13 18:25:01 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-07-13 18:25:01 -0700
commit8af55ca4dd7eeb098b5c2e69bc7a9171c893269a (patch)
tree28260dce3d03d0593741f7dd5688657245c4a7bf /core/java
parent3139297f1eda3e34d17a2b182ae5d791da837542 (diff)
parent78c9d0d2c5eb4d5687ae7cbe41155159329ad68f (diff)
downloadframeworks_base-8af55ca4dd7eeb098b5c2e69bc7a9171c893269a.zip
frameworks_base-8af55ca4dd7eeb098b5c2e69bc7a9171c893269a.tar.gz
frameworks_base-8af55ca4dd7eeb098b5c2e69bc7a9171c893269a.tar.bz2
Merge change 7008 into donut
* changes: Adding Utterance ID to the TtsService.
Diffstat (limited to 'core/java')
-rwxr-xr-xcore/java/android/speech/tts/ITts.aidl4
-rwxr-xr-xcore/java/android/speech/tts/ITtsCallback.aidl2
-rwxr-xr-x[-rw-r--r--]core/java/android/speech/tts/TextToSpeech.java78
3 files changed, 76 insertions, 8 deletions
diff --git a/core/java/android/speech/tts/ITts.aidl b/core/java/android/speech/tts/ITts.aidl
index 5b18b5d..1812188 100755
--- a/core/java/android/speech/tts/ITts.aidl
+++ b/core/java/android/speech/tts/ITts.aidl
@@ -55,9 +55,9 @@ interface ITts {
void addEarconFile(in String callingApp, in String earcon, in String filename);
- void registerCallback(ITtsCallback cb);
+ int registerCallback(in String callingApp, ITtsCallback cb);
- void unregisterCallback(ITtsCallback cb);
+ int unregisterCallback(in String callingApp, ITtsCallback cb);
int playSilence(in String callingApp, in long duration, in int queueMode, in String[] params);
}
diff --git a/core/java/android/speech/tts/ITtsCallback.aidl b/core/java/android/speech/tts/ITtsCallback.aidl
index 48ed73e..c9898eb 100755
--- a/core/java/android/speech/tts/ITtsCallback.aidl
+++ b/core/java/android/speech/tts/ITtsCallback.aidl
@@ -23,5 +23,5 @@ package android.speech.tts;
* {@hide}
*/
oneway interface ITtsCallback {
- void markReached(String mark);
+ void utteranceCompleted(String utteranceId);
}
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index 2369535..a2e70b8 100644..100755
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -99,6 +99,18 @@ public class TextToSpeech {
}
/**
+ * Called when the TTS has completed saying something that has an utterance ID set.
+ *
+ * The OnUtteranceCompletedListener must implement the onUtteranceCompleted function.
+ * onUtteranceCompleted is passed a String that is the utteranceId given in
+ * the original speak call.
+ */
+ public interface OnUtteranceCompletedListener {
+ public void onUtteranceCompleted(String utteranceId);
+ }
+
+
+ /**
* Internal constants for the TTS functionality
*
* {@hide}
@@ -147,6 +159,7 @@ public class TextToSpeech {
private ServiceConnection mServiceConnection;
private ITts mITts = null;
+ private ITtsCallback mITtscallback = null;
private Context mContext = null;
private String mPackageName = "";
private OnInitListener mInitListener = null;
@@ -178,6 +191,7 @@ public class TextToSpeech {
mCachedParams[Engine.TTS_PARAM_POSITION_COUNTRY] = Engine.TTS_KEY_PARAM_COUNTRY;
mCachedParams[Engine.TTS_PARAM_POSITION_VARIANT] = Engine.TTS_KEY_PARAM_VARIANT;
mCachedParams[Engine.TTS_PARAM_POSITION_STREAM] = Engine.TTS_KEY_PARAM_STREAM;
+ mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID] = Engine.TTS_KEY_PARAM_UTTERANCE_ID;
mCachedParams[Engine.TTS_PARAM_POSITION_RATE + 1] =
String.valueOf(Engine.FALLBACK_TTS_DEFAULT_RATE);
@@ -189,7 +203,7 @@ public class TextToSpeech {
mCachedParams[Engine.TTS_PARAM_POSITION_STREAM + 1] =
String.valueOf(Engine.TTS_DEFAULT_STREAM);
- mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID+ 1] = "";
+ mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID + 1] = "";
initTts();
}
@@ -380,7 +394,7 @@ public class TextToSpeech {
}
extra = params.get(Engine.TTS_KEY_PARAM_UTTERANCE_ID);
if (extra != null) {
- mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID] = extra;
+ mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID + 1] = extra;
}
}
result = mITts.speak(mPackageName, text, queueMode, mCachedParams);
@@ -437,7 +451,7 @@ public class TextToSpeech {
}
extra = params.get(Engine.TTS_KEY_PARAM_UTTERANCE_ID);
if (extra != null) {
- mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID] = extra;
+ mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID + 1] = extra;
}
}
result = mITts.playEarcon(mPackageName, earcon, queueMode, null);
@@ -477,13 +491,19 @@ public class TextToSpeech {
*
* @return Code indicating success or failure. See TTS_ERROR and TTS_SUCCESS.
*/
- public int playSilence(long durationInMs, int queueMode) {
+ public int playSilence(long durationInMs, int queueMode, HashMap<String,String> params) {
synchronized (mStartLock) {
int result = TTS_ERROR;
if (!mStarted) {
return result;
}
try {
+ if ((params != null) && (!params.isEmpty())) {
+ String extra = params.get(Engine.TTS_KEY_PARAM_UTTERANCE_ID);
+ if (extra != null) {
+ mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID + 1] = extra;
+ }
+ }
result = mITts.playSilence(mPackageName, durationInMs, queueMode, mCachedParams);
} catch (RemoteException e) {
// TTS died; restart it.
@@ -845,7 +865,7 @@ public class TextToSpeech {
// no need to read the stream type here
String extra = params.get(Engine.TTS_KEY_PARAM_UTTERANCE_ID);
if (extra != null) {
- mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID] = extra;
+ mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID + 1] = extra;
}
}
if (mITts.synthesizeToFile(mPackageName, text, mCachedParams, filename)){
@@ -887,4 +907,52 @@ public class TextToSpeech {
mCachedParams[Engine.TTS_PARAM_POSITION_UTTERANCE_ID+ 1] = "";
}
+ /**
+ * Sets the OnUtteranceCompletedListener that will fire when an utterance completes.
+ *
+ * @param listener
+ * The OnUtteranceCompletedListener
+ *
+ * @return Code indicating success or failure. See TTS_ERROR and TTS_SUCCESS.
+ */
+ public int setOnUtteranceCompletedListener(
+ final OnUtteranceCompletedListener listener) {
+ synchronized (mStartLock) {
+ int result = TTS_ERROR;
+ if (!mStarted) {
+ return result;
+ }
+ mITtscallback = new ITtsCallback.Stub() {
+ public void utteranceCompleted(String utteranceId) throws RemoteException {
+ if (listener != null) {
+ listener.onUtteranceCompleted(utteranceId);
+ }
+ }
+ };
+ try {
+ result = mITts.registerCallback(mPackageName, mITtscallback);
+ } catch (RemoteException e) {
+ // TTS died; restart it.
+ Log.e("TextToSpeech.java - registerCallback", "RemoteException");
+ e.printStackTrace();
+ mStarted = false;
+ initTts();
+ } catch (NullPointerException e) {
+ // TTS died; restart it.
+ Log.e("TextToSpeech.java - registerCallback", "NullPointerException");
+ e.printStackTrace();
+ mStarted = false;
+ initTts();
+ } catch (IllegalStateException e) {
+ // TTS died; restart it.
+ Log.e("TextToSpeech.java - registerCallback", "IllegalStateException");
+ e.printStackTrace();
+ mStarted = false;
+ initTts();
+ } finally {
+ return result;
+ }
+ }
+ }
+
}