diff options
| author | Niels Egberts <nielse@google.com> | 2016-12-23 15:32:11 +0000 |
|---|---|---|
| committer | Niels Egberts <nielse@google.com> | 2016-12-23 15:39:05 +0000 |
| commit | 01dedf59db924726ee323aac89708031ce8f320f (patch) | |
| tree | 5f2db30804a3383a6d7f1987b3edc2db06f50a8c /core/java/android | |
| parent | 6e22c50d7b06a6296182d9230f53b10cf5bd41b3 (diff) | |
Remove refernces to V1 API, as V2 doesn't exist anymore.
Also ran formatter on modified lines.
Test: Refactor only, CTS tests still passing.
Change-Id: I1309cfa8e9e731d3450c13d96038e6b5d53a12e1
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/speech/tts/EventLogger.java (renamed from core/java/android/speech/tts/EventLoggerV1.java) | 10 | ||||
| -rw-r--r-- | core/java/android/speech/tts/TextToSpeechService.java | 457 | ||||
| -rw-r--r-- | core/java/android/speech/tts/TtsEngines.java | 4 |
3 files changed, 266 insertions, 205 deletions
diff --git a/core/java/android/speech/tts/EventLoggerV1.java b/core/java/android/speech/tts/EventLogger.java index 2b02b43cdecd..f03df311731a 100644 --- a/core/java/android/speech/tts/EventLoggerV1.java +++ b/core/java/android/speech/tts/EventLogger.java @@ -18,14 +18,14 @@ package android.speech.tts; import android.text.TextUtils; /** - * Writes data about a given speech synthesis request for V1 API to the event - * logs. The data that is logged includes the calling app, length of the - * utterance, speech rate / pitch, the latency, and overall time taken. + * Writes data about a given speech synthesis request to the event logs. The data that is logged + * includes the calling app, length of the utterance, speech rate / pitch, the latency, and overall + * time taken. */ -class EventLoggerV1 extends AbstractEventLogger { +class EventLogger extends AbstractEventLogger { private final SynthesisRequest mRequest; - EventLoggerV1(SynthesisRequest request, int callerUid, int callerPid, String serviceApp) { + EventLogger(SynthesisRequest request, int callerUid, int callerPid, String serviceApp) { super(callerUid, callerPid, serviceApp); mRequest = request; } diff --git a/core/java/android/speech/tts/TextToSpeechService.java b/core/java/android/speech/tts/TextToSpeechService.java index 9b238ce64c97..caedcb313745 100644 --- a/core/java/android/speech/tts/TextToSpeechService.java +++ b/core/java/android/speech/tts/TextToSpeechService.java @@ -226,17 +226,14 @@ public abstract class TextToSpeechService extends Service { protected abstract void onStop(); /** - * Tells the service to synthesize speech from the given text. This method - * should block until the synthesis is finished. Used for requests from V1 - * clients ({@link android.speech.tts.TextToSpeech}). Called on the synthesis - * thread. + * Tells the service to synthesize speech from the given text. This method should block until + * the synthesis is finished. Called on the synthesis thread. * * @param request The synthesis request. - * @param callback The callback that the engine must use to make data - * available for playback or for writing to a file. + * @param callback The callback that the engine must use to make data available for playback or + * for writing to a file. */ - protected abstract void onSynthesizeText(SynthesisRequest request, - SynthesisCallback callback); + protected abstract void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback); /** * Queries the service for a set of features supported for a given language. @@ -708,8 +705,7 @@ public abstract class TextToSpeechService extends Service { } /** Create AudioOutputParams from A {@link SynthesisRequest#getParams()} bundle */ - static AudioOutputParams createFromV1ParamsBundle(Bundle paramsBundle, - boolean isSpeech) { + static AudioOutputParams createFromParamsBundle(Bundle paramsBundle, boolean isSpeech) { if (paramsBundle == null) { return new AudioOutputParams(); } @@ -897,16 +893,19 @@ public abstract class TextToSpeechService extends Service { } /** - * UtteranceSpeechItem for V1 API speech items. V1 API speech items keep - * synthesis parameters in a single Bundle passed as parameter. This class - * allow subclasses to access them conveniently. + * Synthesis parameters are kept in a single Bundle passed as parameter. This class allow + * subclasses to access them conveniently. */ - private abstract class SpeechItemV1 extends UtteranceSpeechItem { + private abstract class UtteranceSpeechItemWithParams extends UtteranceSpeechItem { protected final Bundle mParams; protected final String mUtteranceId; - SpeechItemV1(Object callerIdentity, int callerUid, int callerPid, - Bundle params, String utteranceId) { + UtteranceSpeechItemWithParams( + Object callerIdentity, + int callerUid, + int callerPid, + Bundle params, + String utteranceId) { super(callerIdentity, callerUid, callerPid); mParams = params; mUtteranceId = utteranceId; @@ -930,11 +929,11 @@ public abstract class TextToSpeechService extends Service { } AudioOutputParams getAudioParams() { - return AudioOutputParams.createFromV1ParamsBundle(mParams, true); + return AudioOutputParams.createFromParamsBundle(mParams, true); } } - class SynthesisSpeechItemV1 extends SpeechItemV1 { + class SynthesisSpeechItem extends UtteranceSpeechItemWithParams { // Never null. private final CharSequence mText; private final SynthesisRequest mSynthesisRequest; @@ -942,19 +941,23 @@ public abstract class TextToSpeechService extends Service { // Non null after synthesis has started, and all accesses // guarded by 'this'. private AbstractSynthesisCallback mSynthesisCallback; - private final EventLoggerV1 mEventLogger; + private final EventLogger mEventLogger; private final int mCallerUid; - public SynthesisSpeechItemV1(Object callerIdentity, int callerUid, int callerPid, - Bundle params, String utteranceId, CharSequence text) { + public SynthesisSpeechItem( + Object callerIdentity, + int callerUid, + int callerPid, + Bundle params, + String utteranceId, + CharSequence text) { super(callerIdentity, callerUid, callerPid, params, utteranceId); mText = text; mCallerUid = callerUid; mSynthesisRequest = new SynthesisRequest(mText, mParams); mDefaultLocale = getSettingsLocale(); setRequestParams(mSynthesisRequest); - mEventLogger = new EventLoggerV1(mSynthesisRequest, callerUid, callerPid, - mPackageName); + mEventLogger = new EventLogger(mSynthesisRequest, callerUid, callerPid, mPackageName); } public CharSequence getText() { @@ -1048,11 +1051,16 @@ public abstract class TextToSpeechService extends Service { } } - private class SynthesisToFileOutputStreamSpeechItemV1 extends SynthesisSpeechItemV1 { + private class SynthesisToFileOutputStreamSpeechItem extends SynthesisSpeechItem { private final FileOutputStream mFileOutputStream; - public SynthesisToFileOutputStreamSpeechItemV1(Object callerIdentity, int callerUid, - int callerPid, Bundle params, String utteranceId, CharSequence text, + public SynthesisToFileOutputStreamSpeechItem( + Object callerIdentity, + int callerUid, + int callerPid, + Bundle params, + String utteranceId, + CharSequence text, FileOutputStream fileOutputStream) { super(callerIdentity, callerUid, callerPid, params, utteranceId, text); mFileOutputStream = fileOutputStream; @@ -1075,11 +1083,16 @@ public abstract class TextToSpeechService extends Service { } } - private class AudioSpeechItemV1 extends SpeechItemV1 { + private class AudioSpeechItem extends UtteranceSpeechItemWithParams { private final AudioPlaybackQueueItem mItem; - public AudioSpeechItemV1(Object callerIdentity, int callerUid, int callerPid, - Bundle params, String utteranceId, Uri uri) { + public AudioSpeechItem( + Object callerIdentity, + int callerUid, + int callerPid, + Bundle params, + String utteranceId, + Uri uri) { super(callerIdentity, callerUid, callerPid, params, utteranceId); mItem = new AudioPlaybackQueueItem(this, getCallerIdentity(), TextToSpeechService.this, uri, getAudioParams()); @@ -1107,7 +1120,7 @@ public abstract class TextToSpeechService extends Service { @Override AudioOutputParams getAudioParams() { - return AudioOutputParams.createFromV1ParamsBundle(mParams, false); + return AudioOutputParams.createFromParamsBundle(mParams, false); } } @@ -1214,202 +1227,252 @@ public abstract class TextToSpeechService extends Service { } /** - * Binder returned from {@code #onBind(Intent)}. The methods in this class can be - * called called from several different threads. + * Binder returned from {@code #onBind(Intent)}. The methods in this class can be called called + * from several different threads. */ // NOTE: All calls that are passed in a calling app are interned so that // 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, 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, utteranceId, text); - return mSynthHandler.enqueueSpeechItem(queueMode, item); - } - - @Override - public int synthesizeToFileDescriptor(IBinder caller, CharSequence text, ParcelFileDescriptor - fileDescriptor, Bundle params, String utteranceId) { - if (!checkNonNull(caller, text, fileDescriptor, params)) { - return TextToSpeech.ERROR; - } - - // In test env, ParcelFileDescriptor instance may be EXACTLY the same - // one that is used by client. And it will be closed by a client, thus - // preventing us from writing anything to it. - final ParcelFileDescriptor sameFileDescriptor = ParcelFileDescriptor.adoptFd( - fileDescriptor.detachFd()); - - SpeechItem item = new SynthesisToFileOutputStreamSpeechItemV1(caller, - Binder.getCallingUid(), Binder.getCallingPid(), params, utteranceId, text, - new ParcelFileDescriptor.AutoCloseOutputStream(sameFileDescriptor)); - return mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item); - } + private final ITextToSpeechService.Stub mBinder = + new ITextToSpeechService.Stub() { + @Override + public int speak( + IBinder caller, + CharSequence text, + int queueMode, + Bundle params, + String utteranceId) { + if (!checkNonNull(caller, text, params)) { + return TextToSpeech.ERROR; + } - @Override - public int playAudio(IBinder caller, Uri audioUri, int queueMode, Bundle params, - String utteranceId) { - if (!checkNonNull(caller, audioUri, params)) { - return TextToSpeech.ERROR; - } + SpeechItem item = + new SynthesisSpeechItem( + caller, + Binder.getCallingUid(), + Binder.getCallingPid(), + params, + utteranceId, + text); + return mSynthHandler.enqueueSpeechItem(queueMode, item); + } - SpeechItem item = new AudioSpeechItemV1(caller, - Binder.getCallingUid(), Binder.getCallingPid(), params, utteranceId, audioUri); - return mSynthHandler.enqueueSpeechItem(queueMode, item); - } + @Override + public int synthesizeToFileDescriptor( + IBinder caller, + CharSequence text, + ParcelFileDescriptor fileDescriptor, + Bundle params, + String utteranceId) { + if (!checkNonNull(caller, text, fileDescriptor, params)) { + return TextToSpeech.ERROR; + } - @Override - public int playSilence(IBinder caller, long duration, int queueMode, String utteranceId) { - if (!checkNonNull(caller)) { - return TextToSpeech.ERROR; - } + // In test env, ParcelFileDescriptor instance may be EXACTLY the same + // one that is used by client. And it will be closed by a client, thus + // preventing us from writing anything to it. + final ParcelFileDescriptor sameFileDescriptor = + ParcelFileDescriptor.adoptFd(fileDescriptor.detachFd()); + + SpeechItem item = + new SynthesisToFileOutputStreamSpeechItem( + caller, + Binder.getCallingUid(), + Binder.getCallingPid(), + params, + utteranceId, + text, + new ParcelFileDescriptor.AutoCloseOutputStream( + sameFileDescriptor)); + return mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item); + } - SpeechItem item = new SilenceSpeechItem(caller, - Binder.getCallingUid(), Binder.getCallingPid(), utteranceId, duration); - return mSynthHandler.enqueueSpeechItem(queueMode, item); - } + @Override + public int playAudio( + IBinder caller, + Uri audioUri, + int queueMode, + Bundle params, + String utteranceId) { + if (!checkNonNull(caller, audioUri, params)) { + return TextToSpeech.ERROR; + } - @Override - public boolean isSpeaking() { - return mSynthHandler.isSpeaking() || mAudioPlaybackHandler.isSpeaking(); - } + SpeechItem item = + new AudioSpeechItem( + caller, + Binder.getCallingUid(), + Binder.getCallingPid(), + params, + utteranceId, + audioUri); + return mSynthHandler.enqueueSpeechItem(queueMode, item); + } - @Override - public int stop(IBinder caller) { - if (!checkNonNull(caller)) { - return TextToSpeech.ERROR; - } + @Override + public int playSilence( + IBinder caller, long duration, int queueMode, String utteranceId) { + if (!checkNonNull(caller)) { + return TextToSpeech.ERROR; + } - return mSynthHandler.stopForApp(caller); - } + SpeechItem item = + new SilenceSpeechItem( + caller, + Binder.getCallingUid(), + Binder.getCallingPid(), + utteranceId, + duration); + return mSynthHandler.enqueueSpeechItem(queueMode, item); + } - @Override - public String[] getLanguage() { - return onGetLanguage(); - } + @Override + public boolean isSpeaking() { + return mSynthHandler.isSpeaking() || mAudioPlaybackHandler.isSpeaking(); + } - @Override - public String[] getClientDefaultLanguage() { - return getSettingsLocale(); - } + @Override + public int stop(IBinder caller) { + if (!checkNonNull(caller)) { + return TextToSpeech.ERROR; + } - /* - * If defaults are enforced, then no language is "available" except - * perhaps the default language selected by the user. - */ - @Override - public int isLanguageAvailable(String lang, String country, String variant) { - if (!checkNonNull(lang)) { - return TextToSpeech.ERROR; - } + return mSynthHandler.stopForApp(caller); + } - return onIsLanguageAvailable(lang, country, variant); - } + @Override + public String[] getLanguage() { + return onGetLanguage(); + } - @Override - public String[] getFeaturesForLanguage(String lang, String country, String variant) { - Set<String> features = onGetFeaturesForLanguage(lang, country, variant); - String[] featuresArray = null; - if (features != null) { - featuresArray = new String[features.size()]; - features.toArray(featuresArray); - } else { - featuresArray = new String[0]; - } - return featuresArray; - } + @Override + public String[] getClientDefaultLanguage() { + return getSettingsLocale(); + } - /* - * There is no point loading a non default language if defaults - * are enforced. - */ - @Override - public int loadLanguage(IBinder caller, String lang, String country, String variant) { - if (!checkNonNull(lang)) { - return TextToSpeech.ERROR; - } - int retVal = onIsLanguageAvailable(lang, country, variant); + /* + * If defaults are enforced, then no language is "available" except + * perhaps the default language selected by the user. + */ + @Override + public int isLanguageAvailable(String lang, String country, String variant) { + if (!checkNonNull(lang)) { + return TextToSpeech.ERROR; + } - if (retVal == TextToSpeech.LANG_AVAILABLE || - retVal == TextToSpeech.LANG_COUNTRY_AVAILABLE || - retVal == TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE) { + return onIsLanguageAvailable(lang, country, variant); + } - SpeechItem item = new LoadLanguageItem(caller, Binder.getCallingUid(), - Binder.getCallingPid(), lang, country, variant); + @Override + public String[] getFeaturesForLanguage( + String lang, String country, String variant) { + Set<String> features = onGetFeaturesForLanguage(lang, country, variant); + String[] featuresArray = null; + if (features != null) { + featuresArray = new String[features.size()]; + features.toArray(featuresArray); + } else { + featuresArray = new String[0]; + } + return featuresArray; + } - if (mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item) != - TextToSpeech.SUCCESS) { - return TextToSpeech.ERROR; + /* + * There is no point loading a non default language if defaults + * are enforced. + */ + @Override + public int loadLanguage( + IBinder caller, String lang, String country, String variant) { + if (!checkNonNull(lang)) { + return TextToSpeech.ERROR; + } + int retVal = onIsLanguageAvailable(lang, country, variant); + + if (retVal == TextToSpeech.LANG_AVAILABLE + || retVal == TextToSpeech.LANG_COUNTRY_AVAILABLE + || retVal == TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE) { + + SpeechItem item = + new LoadLanguageItem( + caller, + Binder.getCallingUid(), + Binder.getCallingPid(), + lang, + country, + variant); + + if (mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item) + != TextToSpeech.SUCCESS) { + return TextToSpeech.ERROR; + } + } + return retVal; } - } - return retVal; - } - @Override - public List<Voice> getVoices() { - return onGetVoices(); - } + @Override + public List<Voice> getVoices() { + return onGetVoices(); + } - @Override - public int loadVoice(IBinder caller, String voiceName) { - if (!checkNonNull(voiceName)) { - return TextToSpeech.ERROR; - } - int retVal = onIsValidVoiceName(voiceName); - - if (retVal == TextToSpeech.SUCCESS) { - SpeechItem item = new LoadVoiceItem(caller, Binder.getCallingUid(), - Binder.getCallingPid(), voiceName); - if (mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item) != - TextToSpeech.SUCCESS) { - return TextToSpeech.ERROR; + @Override + public int loadVoice(IBinder caller, String voiceName) { + if (!checkNonNull(voiceName)) { + return TextToSpeech.ERROR; + } + int retVal = onIsValidVoiceName(voiceName); + + if (retVal == TextToSpeech.SUCCESS) { + SpeechItem item = + new LoadVoiceItem( + caller, + Binder.getCallingUid(), + Binder.getCallingPid(), + voiceName); + if (mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item) + != TextToSpeech.SUCCESS) { + return TextToSpeech.ERROR; + } + } + return retVal; } - } - return retVal; - } - public String getDefaultVoiceNameFor(String lang, String country, String variant) { - if (!checkNonNull(lang)) { - return null; - } - int retVal = onIsLanguageAvailable(lang, country, variant); + public String getDefaultVoiceNameFor(String lang, String country, String variant) { + if (!checkNonNull(lang)) { + return null; + } + int retVal = onIsLanguageAvailable(lang, country, variant); - if (retVal == TextToSpeech.LANG_AVAILABLE || - retVal == TextToSpeech.LANG_COUNTRY_AVAILABLE || - retVal == TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE) { - return onGetDefaultVoiceNameFor(lang, country, variant); - } else { - return null; - } - } + if (retVal == TextToSpeech.LANG_AVAILABLE + || retVal == TextToSpeech.LANG_COUNTRY_AVAILABLE + || retVal == TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE) { + return onGetDefaultVoiceNameFor(lang, country, variant); + } else { + return null; + } + } - @Override - public void setCallback(IBinder caller, ITextToSpeechCallback cb) { - // Note that passing in a null callback is a valid use case. - if (!checkNonNull(caller)) { - return; - } + @Override + public void setCallback(IBinder caller, ITextToSpeechCallback cb) { + // Note that passing in a null callback is a valid use case. + if (!checkNonNull(caller)) { + return; + } - mCallbacks.setCallback(caller, cb); - } + mCallbacks.setCallback(caller, cb); + } - private String intern(String in) { - // The input parameter will be non null. - return in.intern(); - } + private String intern(String in) { + // The input parameter will be non null. + return in.intern(); + } - private boolean checkNonNull(Object... args) { - for (Object o : args) { - if (o == null) return false; - } - return true; - } - }; + private boolean checkNonNull(Object... args) { + for (Object o : args) { + if (o == null) return false; + } + return true; + } + }; private class CallbackMap extends RemoteCallbackList<ITextToSpeechCallback> { private final HashMap<IBinder, ITextToSpeechCallback> mCallerToCallback diff --git a/core/java/android/speech/tts/TtsEngines.java b/core/java/android/speech/tts/TtsEngines.java index 412eba304e89..a8c3453293ab 100644 --- a/core/java/android/speech/tts/TtsEngines.java +++ b/core/java/android/speech/tts/TtsEngines.java @@ -471,9 +471,7 @@ public class TtsEngines { String[] ret = new String[]{"","",""}; try { // Note that the default locale might have an empty variant - // or language, and we take care that the construction is - // the same as {@link #getV1Locale} i.e no trailing delimiters - // or spaces. + // or language. ret[0] = locale.getISO3Language(); ret[1] = locale.getISO3Country(); ret[2] = locale.getVariant(); |
