diff options
author | Niels Egberts <nielse@google.com> | 2014-06-25 15:30:44 +0100 |
---|---|---|
committer | Niels Egberts <nielse@google.com> | 2014-07-02 15:23:33 +0000 |
commit | df7deefe8ebcbd619f27e2d394d7e5d0d7af33d1 (patch) | |
tree | 8328481b1d69c199a862e22c4d05d9912e9dc5c0 | |
parent | 7028946402e76ef0790c42b350067155a6f901cb (diff) | |
download | frameworks_base-df7deefe8ebcbd619f27e2d394d7e5d0d7af33d1.zip frameworks_base-df7deefe8ebcbd619f27e2d394d7e5d0d7af33d1.tar.gz frameworks_base-df7deefe8ebcbd619f27e2d394d7e5d0d7af33d1.tar.bz2 |
Support for CharSequences in the V1 API.
Two newly deprecated methods:
- TextToSpeech.speak (over TextToSpeech.speak with mandatory utteranceId)
- SynthesisRequest.getText (over SynthesisRequest.getCharSequenceText)
Change-Id: I8a75ed335c91074c72d6ef374ff8b9c79a7c208d
-rw-r--r-- | api/current.txt | 16 | ||||
-rw-r--r-- | core/java/android/speech/tts/ITextToSpeechService.aidl | 13 | ||||
-rw-r--r-- | core/java/android/speech/tts/SynthesisRequest.java | 17 | ||||
-rw-r--r-- | core/java/android/speech/tts/TextToSpeech.java | 225 | ||||
-rw-r--r-- | core/java/android/speech/tts/TextToSpeechService.java | 39 |
5 files changed, 261 insertions, 49 deletions
diff --git a/api/current.txt b/api/current.txt index 1912a6f..166beb8 100644 --- a/api/current.txt +++ b/api/current.txt @@ -26580,13 +26580,15 @@ package android.speech.tts { public final class SynthesisRequest { ctor public SynthesisRequest(java.lang.String, android.os.Bundle); + ctor public SynthesisRequest(java.lang.CharSequence, android.os.Bundle); method public int getCallerUid(); + method public java.lang.CharSequence getCharSequenceText(); method public java.lang.String getCountry(); method public java.lang.String getLanguage(); method public android.os.Bundle getParams(); method public int getPitch(); method public int getSpeechRate(); - method public java.lang.String getText(); + method public deprecated java.lang.String getText(); method public java.lang.String getVariant(); } @@ -26596,7 +26598,9 @@ package android.speech.tts { method public int addEarcon(java.lang.String, java.lang.String, int); method public int addEarcon(java.lang.String, java.lang.String); method public int addSpeech(java.lang.String, java.lang.String, int); + method public int addSpeech(java.lang.CharSequence, java.lang.String, int); method public int addSpeech(java.lang.String, java.lang.String); + method public int addSpeech(java.lang.CharSequence, java.lang.String); method public boolean areDefaultsEnforced(); method public java.lang.String getDefaultEngine(); method public java.util.Locale getDefaultLanguage(); @@ -26606,7 +26610,9 @@ package android.speech.tts { method public static int getMaxSpeechInputLength(); method public int isLanguageAvailable(java.util.Locale); method public boolean isSpeaking(); - method public int playEarcon(java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>); + method public int playEarcon(java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>, java.lang.String); + method public deprecated int playEarcon(java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>); + method public int playSilence(long, int, java.util.HashMap<java.lang.String, java.lang.String>, java.lang.String); method public int playSilence(long, int, java.util.HashMap<java.lang.String, java.lang.String>); method public deprecated int setEngineByPackageName(java.lang.String); method public int setLanguage(java.util.Locale); @@ -26615,9 +26621,11 @@ package android.speech.tts { method public int setPitch(float); method public int setSpeechRate(float); method public void shutdown(); - method public int speak(java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>); + method public int speak(java.lang.CharSequence, int, java.util.HashMap<java.lang.String, java.lang.String>, java.lang.String); + method public deprecated int speak(java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>); method public int stop(); - method public int synthesizeToFile(java.lang.String, java.util.HashMap<java.lang.String, java.lang.String>, java.lang.String); + method public deprecated int synthesizeToFile(java.lang.String, java.util.HashMap<java.lang.String, java.lang.String>, java.lang.String); + method public int synthesizeToFile(java.lang.CharSequence, java.util.HashMap<java.lang.String, java.lang.String>, java.lang.String, java.lang.String); field public static final java.lang.String ACTION_TTS_QUEUE_PROCESSING_COMPLETED = "android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED"; field public static final int ERROR = -1; // 0xffffffff field public static final int ERROR_INVALID_REQUEST = -8; // 0xfffffff8 diff --git a/core/java/android/speech/tts/ITextToSpeechService.aidl b/core/java/android/speech/tts/ITextToSpeechService.aidl index 4d322df..694f25a 100644 --- a/core/java/android/speech/tts/ITextToSpeechService.aidl +++ b/core/java/android/speech/tts/ITextToSpeechService.aidl @@ -36,8 +36,10 @@ interface ITextToSpeechService { * @param text The text to synthesize. * @param queueMode Determines what to do to requests already in the queue. * @param param Request parameters. + * @param utteranceId Unique identifier of synthesized utterance. */ - int speak(in IBinder callingInstance, in String text, in int queueMode, in Bundle params); + int speak(in IBinder callingInstance, in CharSequence text, in int queueMode, in Bundle params, + String utteranceId); /** * Tells the engine to synthesize some speech and write it to a file. @@ -47,10 +49,11 @@ interface ITextToSpeechService { * @param text The text to synthesize. * @param fileDescriptor The file descriptor to write the synthesized audio to. Has to be writable. + * @param utteranceId Unique identifier of synthesized utterance. * @param param Request parameters. */ - int synthesizeToFileDescriptor(in IBinder callingInstance, in String text, - in ParcelFileDescriptor fileDescriptor, in Bundle params); + int synthesizeToFileDescriptor(in IBinder callingInstance, in CharSequence text, + in ParcelFileDescriptor fileDescriptor, in Bundle params, String utteranceId); /** * Plays an existing audio resource. @@ -59,9 +62,11 @@ interface ITextToSpeechService { * TextToSpeech object. * @param audioUri URI for the audio resource (a file or android.resource URI) * @param queueMode Determines what to do to requests already in the queue. + * @param utteranceId Unique identifier of synthesized utterance. * @param param Request parameters. */ - int playAudio(in IBinder callingInstance, in Uri audioUri, in int queueMode, in Bundle params); + int playAudio(in IBinder callingInstance, in Uri audioUri, in int queueMode, in Bundle params, + String utteranceId); /** * Plays silence. diff --git a/core/java/android/speech/tts/SynthesisRequest.java b/core/java/android/speech/tts/SynthesisRequest.java index 12a026b..eaacc06 100644 --- a/core/java/android/speech/tts/SynthesisRequest.java +++ b/core/java/android/speech/tts/SynthesisRequest.java @@ -34,7 +34,7 @@ import android.os.Bundle; * and {@link TextToSpeech#synthesizeToFile}. */ public final class SynthesisRequest { - private final String mText; + private final CharSequence mText; private final Bundle mParams; private String mLanguage; private String mCountry; @@ -49,10 +49,25 @@ public final class SynthesisRequest { mParams = new Bundle(params); } + public SynthesisRequest(CharSequence text, Bundle params) { + mText = text; + // Makes a copy of params. + mParams = new Bundle(params); + } + /** * Gets the text which should be synthesized. + * @deprecated As of API level 20, replaced by {@link #getCharSequenceText}. */ + @Deprecated public String getText() { + return mText.toString(); + } + + /** + * Gets the text which should be synthesized. + */ + public CharSequence getCharSequenceText() { return mText; } diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index 0d2b69b..457be22 100644 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -593,7 +593,7 @@ public class TextToSpeech { // too. private final boolean mUseFallback; private final Map<String, Uri> mEarcons; - private final Map<String, Uri> mUtterances; + private final Map<CharSequence, Uri> mUtterances; private final Bundle mParams = new Bundle(); private final TtsEngines mEnginesHelper; private final String mPackageName; @@ -644,7 +644,7 @@ public class TextToSpeech { mUseFallback = useFallback; mEarcons = new HashMap<String, Uri>(); - mUtterances = new HashMap<String, Uri>(); + mUtterances = new HashMap<CharSequence, Uri>(); mUtteranceProgressListener = null; mEnginesHelper = new TtsEngines(mContext); @@ -825,6 +825,40 @@ public class TextToSpeech { } /** + * Adds a mapping between a CharSequence (may be spanned with TtsSpans) of text + * and a sound resource in a package. After a call to this method, subsequent calls to + * {@link #speak(String, int, HashMap)} will play the specified sound resource + * if it is available, or synthesize the text it is missing. + * + * @param text + * The string of text. Example: <code>"south_south_east"</code> + * + * @param packagename + * Pass the packagename of the application that contains the + * resource. If the resource is in your own application (this is + * the most common case), then put the packagename of your + * application here.<br/> + * Example: <b>"com.google.marvin.compass"</b><br/> + * The packagename can be found in the AndroidManifest.xml of + * your application. + * <p> + * <code><manifest xmlns:android="..." + * package="<b>com.google.marvin.compass</b>"></code> + * </p> + * + * @param resourceId + * Example: <code>R.raw.south_south_east</code> + * + * @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}. + */ + public int addSpeech(CharSequence text, String packagename, int resourceId) { + synchronized (mStartLock) { + mUtterances.put(text, makeResourceUri(packagename, resourceId)); + return SUCCESS; + } + } + + /** * Adds a mapping between a string of text and a sound file. Using this, it * is possible to add custom pronounciations for a string of text. * After a call to this method, subsequent calls to {@link #speak(String, int, HashMap)} @@ -846,6 +880,28 @@ public class TextToSpeech { } } + /** + * Adds a mapping between a CharSequence (may be spanned with TtsSpans and a sound file. + * Using this, it is possible to add custom pronounciations for a string of text. + * After a call to this method, subsequent calls to {@link #speak(String, int, HashMap)} + * will play the specified sound resource if it is available, or synthesize the text it is + * missing. + * + * @param text + * The string of text. Example: <code>"south_south_east"</code> + * @param filename + * The full path to the sound file (for example: + * "/sdcard/mysounds/hello.wav") + * + * @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}. + */ + public int addSpeech(CharSequence text, String filename) { + synchronized (mStartLock) { + mUtterances.put(text, Uri.parse(filename)); + return SUCCESS; + } + } + /** * Adds a mapping between a string of text and a sound resource in a @@ -910,7 +966,8 @@ public class TextToSpeech { } /** - * Speaks the string using the specified queuing strategy and speech parameters. + * Speaks the text using the specified queuing strategy and speech parameters, the text may + * be spanned with TtsSpans. * This method is asynchronous, i.e. the method just adds the request to the queue of TTS * requests and then returns. The synthesis might not have finished (or even started!) at the * time when this method returns. In order to reliably detect errors during synthesis, @@ -924,32 +981,68 @@ public class TextToSpeech { * @param params Parameters for the request. Can be null. * Supported parameter names: * {@link Engine#KEY_PARAM_STREAM}, - * {@link Engine#KEY_PARAM_UTTERANCE_ID}, * {@link Engine#KEY_PARAM_VOLUME}, * {@link Engine#KEY_PARAM_PAN}. * Engine specific parameters may be passed in but the parameter keys * must be prefixed by the name of the engine they are intended for. For example * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the * engine named "com.svox.pico" if it is being used. + * @param utteranceId An unique identifier for this request. * * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the speak operation. */ - public int speak(final String text, final int queueMode, final HashMap<String, String> params) { + public int speak(final CharSequence text, + final int queueMode, + final HashMap<String, String> params, + final String utteranceId) { return runAction(new Action<Integer>() { @Override public Integer run(ITextToSpeechService service) throws RemoteException { Uri utteranceUri = mUtterances.get(text); if (utteranceUri != null) { return service.playAudio(getCallerIdentity(), utteranceUri, queueMode, - getParams(params)); + getParams(params), utteranceId); } else { - return service.speak(getCallerIdentity(), text, queueMode, getParams(params)); + return service.speak(getCallerIdentity(), text, queueMode, getParams(params), + utteranceId); } } }, ERROR, "speak"); } /** + * Speaks the string using the specified queuing strategy and speech parameters. + * This method is asynchronous, i.e. the method just adds the request to the queue of TTS + * requests and then returns. The synthesis might not have finished (or even started!) at the + * time when this method returns. In order to reliably detect errors during synthesis, + * we recommend setting an utterance progress listener (see + * {@link #setOnUtteranceProgressListener}) and using the + * {@link Engine#KEY_PARAM_UTTERANCE_ID} parameter. + * + * @param text The string of text to be spoken. No longer than + * {@link #getMaxSpeechInputLength()} characters. + * @param queueMode The queuing strategy to use, {@link #QUEUE_ADD} or {@link #QUEUE_FLUSH}. + * @param params Parameters for the request. Can be null. + * Supported parameter names: + * {@link Engine#KEY_PARAM_STREAM}, + * {@link Engine#KEY_PARAM_UTTERANCE_ID}, + * {@link Engine#KEY_PARAM_VOLUME}, + * {@link Engine#KEY_PARAM_PAN}. + * Engine specific parameters may be passed in but the parameter keys + * must be prefixed by the name of the engine they are intended for. For example + * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the + * engine named "com.svox.pico" if it is being used. + * + * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the speak operation. + * @deprecated As of API level 20, replaced by + * {@link #speak(CharSequence, int, HashMap, String)}. + */ + @Deprecated + public int speak(final String text, final int queueMode, final HashMap<String, String> params) { + return speak(text, queueMode, params, params == null ? null : params.get(Engine.KEY_PARAM_UTTERANCE_ID)); + } + + /** * Plays the earcon using the specified queueing mode and parameters. * The earcon must already have been added with {@link #addEarcon(String, String)} or * {@link #addEarcon(String, String, int)}. @@ -965,7 +1058,6 @@ public class TextToSpeech { * @param params Parameters for the request. Can be null. * Supported parameter names: * {@link Engine#KEY_PARAM_STREAM}, - * {@link Engine#KEY_PARAM_UTTERANCE_ID}. * Engine specific parameters may be passed in but the parameter keys * must be prefixed by the name of the engine they are intended for. For example * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the @@ -974,7 +1066,7 @@ public class TextToSpeech { * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the playEarcon operation. */ public int playEarcon(final String earcon, final int queueMode, - final HashMap<String, String> params) { + final HashMap<String, String> params, final String utteranceId) { return runAction(new Action<Integer>() { @Override public Integer run(ITextToSpeechService service) throws RemoteException { @@ -983,12 +1075,44 @@ public class TextToSpeech { return ERROR; } return service.playAudio(getCallerIdentity(), earconUri, queueMode, - getParams(params)); + getParams(params), utteranceId); } }, ERROR, "playEarcon"); } /** + * Plays the earcon using the specified queueing mode and parameters. + * The earcon must already have been added with {@link #addEarcon(String, String)} or + * {@link #addEarcon(String, String, int)}. + * This method is asynchronous, i.e. the method just adds the request to the queue of TTS + * requests and then returns. The synthesis might not have finished (or even started!) at the + * time when this method returns. In order to reliably detect errors during synthesis, + * we recommend setting an utterance progress listener (see + * {@link #setOnUtteranceProgressListener}) and using the + * {@link Engine#KEY_PARAM_UTTERANCE_ID} parameter. + * + * @param earcon The earcon that should be played + * @param queueMode {@link #QUEUE_ADD} or {@link #QUEUE_FLUSH}. + * @param params Parameters for the request. Can be null. + * Supported parameter names: + * {@link Engine#KEY_PARAM_STREAM}, + * {@link Engine#KEY_PARAM_UTTERANCE_ID}. + * Engine specific parameters may be passed in but the parameter keys + * must be prefixed by the name of the engine they are intended for. For example + * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the + * engine named "com.svox.pico" if it is being used. + * + * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the playEarcon operation. + * @deprecated As of API level 20, replaced by + * {@link #playEarcon(String, int, HashMap, String)}. + */ + @Deprecated + public int playEarcon(final String earcon, final int queueMode, + final HashMap<String, String> params) { + return playEarcon(earcon, queueMode, params, params == null ? null : params.get(Engine.KEY_PARAM_UTTERANCE_ID)); + } + + /** * Plays silence for the specified amount of time using the specified * queue mode. * This method is asynchronous, i.e. the method just adds the request to the queue of TTS @@ -1001,27 +1125,55 @@ public class TextToSpeech { * @param durationInMs The duration of the silence. * @param queueMode {@link #QUEUE_ADD} or {@link #QUEUE_FLUSH}. * @param params Parameters for the request. Can be null. - * Supported parameter names: - * {@link Engine#KEY_PARAM_UTTERANCE_ID}. * Engine specific parameters may be passed in but the parameter keys * must be prefixed by the name of the engine they are intended for. For example * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the * engine named "com.svox.pico" if it is being used. + * @param utteranceId An unique identifier for this request. * * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the playSilence operation. */ public int playSilence(final long durationInMs, final int queueMode, - final HashMap<String, String> params) { + final HashMap<String, String> params, final String utteranceId) { return runAction(new Action<Integer>() { @Override public Integer run(ITextToSpeechService service) throws RemoteException { - return service.playSilence(getCallerIdentity(), durationInMs, queueMode, - params == null ? null : params.get(Engine.KEY_PARAM_UTTERANCE_ID)); + return service.playSilence(getCallerIdentity(), durationInMs, queueMode, utteranceId); } }, ERROR, "playSilence"); } /** + * Plays silence for the specified amount of time using the specified + * queue mode. + * This method is asynchronous, i.e. the method just adds the request to the queue of TTS + * requests and then returns. The synthesis might not have finished (or even started!) at the + * time when this method returns. In order to reliably detect errors during synthesis, + * we recommend setting an utterance progress listener (see + * {@link #setOnUtteranceProgressListener}) and using the + * {@link Engine#KEY_PARAM_UTTERANCE_ID} parameter. + * + * @param durationInMs The duration of the silence. + * @param queueMode {@link #QUEUE_ADD} or {@link #QUEUE_FLUSH}. + * @param params Parameters for the request. Can be null. + * Supported parameter names: + * {@link Engine#KEY_PARAM_UTTERANCE_ID}. + * Engine specific parameters may be passed in but the parameter keys + * must be prefixed by the name of the engine they are intended for. For example + * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the + * engine named "com.svox.pico" if it is being used. + * + * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the playSilence operation. + * @deprecated As of API level 20, replaced by + * {@link #playEarcon(String, int, HashMap, String)}. + */ + @Deprecated + public int playSilence(final long durationInMs, final int queueMode, + final HashMap<String, String> params) { + return playSilence(durationInMs, queueMode, params, params == null ? null : params.get(Engine.KEY_PARAM_UTTERANCE_ID)); + } + + /** * Queries the engine for the set of features it supports for a given locale. * Features can either be framework defined, e.g. * {@link TextToSpeech.Engine#KEY_FEATURE_NETWORK_SYNTHESIS} or engine specific. @@ -1294,25 +1446,22 @@ public class TextToSpeech { * requests and then returns. The synthesis might not have finished (or even started!) at the * time when this method returns. In order to reliably detect errors during synthesis, * we recommend setting an utterance progress listener (see - * {@link #setOnUtteranceProgressListener}) and using the - * {@link Engine#KEY_PARAM_UTTERANCE_ID} parameter. + * {@link #setOnUtteranceProgressListener}). * * @param text The text that should be synthesized. No longer than * {@link #getMaxSpeechInputLength()} characters. * @param params Parameters for the request. Can be null. - * Supported parameter names: - * {@link Engine#KEY_PARAM_UTTERANCE_ID}. * Engine specific parameters may be passed in but the parameter keys * must be prefixed by the name of the engine they are intended for. For example * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the * engine named "com.svox.pico" if it is being used. * @param filename Absolute file filename to write the generated audio data to.It should be * something like "/sdcard/myappsounds/mysound.wav". - * + * @param utteranceId An unique identifier for this request. * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the synthesizeToFile operation. */ - public int synthesizeToFile(final String text, final HashMap<String, String> params, - final String filename) { + public int synthesizeToFile(final CharSequence text, final HashMap<String, String> params, + final String filename, final String utteranceId) { return runAction(new Action<Integer>() { @Override public Integer run(ITextToSpeechService service) throws RemoteException { @@ -1329,7 +1478,7 @@ public class TextToSpeech { ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE); returnValue = service.synthesizeToFileDescriptor(getCallerIdentity(), text, - fileDescriptor, getParams(params)); + fileDescriptor, getParams(params), utteranceId); fileDescriptor.close(); return returnValue; } catch (FileNotFoundException e) { @@ -1343,6 +1492,36 @@ public class TextToSpeech { }, ERROR, "synthesizeToFile"); } + /** + * Synthesizes the given text to a file using the specified parameters. + * This method is asynchronous, i.e. the method just adds the request to the queue of TTS + * requests and then returns. The synthesis might not have finished (or even started!) at the + * time when this method returns. In order to reliably detect errors during synthesis, + * we recommend setting an utterance progress listener (see + * {@link #setOnUtteranceProgressListener}) and using the + * {@link Engine#KEY_PARAM_UTTERANCE_ID} parameter. + * + * @param text The text that should be synthesized. No longer than + * {@link #getMaxSpeechInputLength()} characters. + * @param params Parameters for the request. Can be null. + * Supported parameter names: + * {@link Engine#KEY_PARAM_UTTERANCE_ID}. + * Engine specific parameters may be passed in but the parameter keys + * must be prefixed by the name of the engine they are intended for. For example + * the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the + * engine named "com.svox.pico" if it is being used. + * @param filename Absolute file filename to write the generated audio data to.It should be + * something like "/sdcard/myappsounds/mysound.wav". + * + * @return {@link #ERROR} or {@link #SUCCESS} of <b>queuing</b> the synthesizeToFile operation. + * @deprecated As of API level 20, replaced by + * {@link #synthesizeToFile(CharSequence, HashMap, String, String)}. + */ + public int synthesizeToFile(final String text, final HashMap<String, String> params, + final String filename) { + return synthesizeToFile(text, params, filename, params.get(Engine.KEY_PARAM_UTTERANCE_ID)); + } + private Bundle getParams(HashMap<String, String> params) { if (params != null && !params.isEmpty()) { Bundle bundle = new Bundle(mParams); diff --git a/core/java/android/speech/tts/TextToSpeechService.java b/core/java/android/speech/tts/TextToSpeechService.java index 5a3c5f7..017be93 100644 --- a/core/java/android/speech/tts/TextToSpeechService.java +++ b/core/java/android/speech/tts/TextToSpeechService.java @@ -637,11 +637,13 @@ public abstract class TextToSpeechService extends Service { */ private abstract class SpeechItemV1 extends UtteranceSpeechItem { protected final Bundle mParams; + protected final String mUtteranceId; SpeechItemV1(Object callerIdentity, int callerUid, int callerPid, - Bundle params) { + Bundle params, String utteranceId) { super(callerIdentity, callerUid, callerPid); mParams = params; + mUtteranceId = utteranceId; } boolean hasLanguage() { @@ -658,7 +660,7 @@ public abstract class TextToSpeechService extends Service { @Override public String getUtteranceId() { - return getStringParam(mParams, Engine.KEY_PARAM_UTTERANCE_ID, null); + return mUtteranceId; } AudioOutputParams getAudioParams() { @@ -668,7 +670,7 @@ public abstract class TextToSpeechService extends Service { class SynthesisSpeechItemV1 extends SpeechItemV1 { // Never null. - private final String mText; + private final CharSequence mText; private final SynthesisRequest mSynthesisRequest; private final String[] mDefaultLocale; // Non null after synthesis has started, and all accesses @@ -678,8 +680,8 @@ public abstract class TextToSpeechService extends Service { private final int mCallerUid; public SynthesisSpeechItemV1(Object callerIdentity, int callerUid, int callerPid, - Bundle params, String text) { - super(callerIdentity, callerUid, callerPid, params); + Bundle params, String utteranceId, CharSequence text) { + super(callerIdentity, callerUid, callerPid, params, utteranceId); mText = text; mCallerUid = callerUid; mSynthesisRequest = new SynthesisRequest(mText, mParams); @@ -689,7 +691,7 @@ public abstract class TextToSpeechService extends Service { mPackageName); } - public String getText() { + public CharSequence getText() { return mText; } @@ -774,8 +776,9 @@ public abstract class TextToSpeechService extends Service { private final FileOutputStream mFileOutputStream; public SynthesisToFileOutputStreamSpeechItemV1(Object callerIdentity, int callerUid, - int callerPid, Bundle params, String text, FileOutputStream fileOutputStream) { - super(callerIdentity, callerUid, callerPid, params, text); + int callerPid, Bundle params, String utteranceId, CharSequence text, + FileOutputStream fileOutputStream) { + super(callerIdentity, callerUid, callerPid, params, utteranceId, text); mFileOutputStream = fileOutputStream; } @@ -801,8 +804,8 @@ public abstract class TextToSpeechService extends Service { private final AudioPlaybackQueueItem mItem; public AudioSpeechItemV1(Object callerIdentity, int callerUid, int callerPid, - Bundle params, Uri uri) { - super(callerIdentity, callerUid, callerPid, params); + Bundle params, String utteranceId, Uri uri) { + super(callerIdentity, callerUid, callerPid, params, utteranceId); mItem = new AudioPlaybackQueueItem(this, getCallerIdentity(), TextToSpeechService.this, uri, getAudioParams()); } @@ -909,19 +912,20 @@ public abstract class TextToSpeechService extends Service { // they can be used as message objects (which are tested for equality using ==). private final ITextToSpeechService.Stub mBinder = new ITextToSpeechService.Stub() { @Override - public int speak(IBinder caller, String text, int queueMode, Bundle params) { + public int speak(IBinder caller, CharSequence text, int queueMode, Bundle params, + String utteranceId) { if (!checkNonNull(caller, text, params)) { return TextToSpeech.ERROR; } SpeechItem item = new SynthesisSpeechItemV1(caller, - Binder.getCallingUid(), Binder.getCallingPid(), params, text); + Binder.getCallingUid(), Binder.getCallingPid(), params, utteranceId, text); return mSynthHandler.enqueueSpeechItem(queueMode, item); } @Override - public int synthesizeToFileDescriptor(IBinder caller, String text, ParcelFileDescriptor - fileDescriptor, Bundle params) { + public int synthesizeToFileDescriptor(IBinder caller, CharSequence text, ParcelFileDescriptor + fileDescriptor, Bundle params, String utteranceId) { if (!checkNonNull(caller, text, fileDescriptor, params)) { return TextToSpeech.ERROR; } @@ -933,19 +937,20 @@ public abstract class TextToSpeechService extends Service { fileDescriptor.detachFd()); SpeechItem item = new SynthesisToFileOutputStreamSpeechItemV1(caller, - Binder.getCallingUid(), Binder.getCallingPid(), params, text, + Binder.getCallingUid(), Binder.getCallingPid(), params, utteranceId, text, new ParcelFileDescriptor.AutoCloseOutputStream(sameFileDescriptor)); return mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item); } @Override - public int playAudio(IBinder caller, Uri audioUri, int queueMode, Bundle params) { + public int playAudio(IBinder caller, Uri audioUri, int queueMode, Bundle params, + String utteranceId) { if (!checkNonNull(caller, audioUri, params)) { return TextToSpeech.ERROR; } SpeechItem item = new AudioSpeechItemV1(caller, - Binder.getCallingUid(), Binder.getCallingPid(), params, audioUri); + Binder.getCallingUid(), Binder.getCallingPid(), params, utteranceId, audioUri); return mSynthHandler.enqueueSpeechItem(queueMode, item); } |