Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b5637ee authored by Przemyslaw Szczepaniak's avatar Przemyslaw Szczepaniak
Browse files

Expose "default tts locale" to the TTS V2 API.

This change allows TTS V2 API client applications to honor the
"default TTS locale" set by the user in the TTS settings.

Note that the TTS V1 API uses 3 character country/language codes
for locale encoding. It's the only system component that does
that. TTS V2 uses the standard, valid Locale objects. The default
TTS locale setting was stored as a 3 character locale string with
"-" as the separator.

This change switches the TTS locale setting format to the output of
Locale.toString() call (on a valid Locale object). Methods used for
reading this value can interpret both forms and try to return a valid
Locale object as an output.

Change-Id: Ice2e6c25a43eb9dd6e17d371ee582c2dae3329c9
parent dad8f819
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26673,6 +26673,7 @@ package android.speech.tts {
  }
  public static final class TextToSpeechClient.EngineStatus {
    method public java.util.Locale getDefaultLocale();
    method public java.lang.String getEnginePackage();
    method public java.util.List<android.speech.tts.VoiceInfo> getVoices();
  }
+7 −5
Original line number Diff line number Diff line
@@ -31,7 +31,8 @@ public final class RequestConfigHelper {

        /**
         * Score positively voices that exactly match the given locale
         * @param locale Reference locale. If null, the default locale will be used.
         * @param locale Reference locale. If null, the system default locale for the
         * current user will be used ({@link Locale#getDefault()}).
         */
        public ExactLocaleMatcher(Locale locale) {
            if (locale == null) {
@@ -55,7 +56,8 @@ public final class RequestConfigHelper {

        /**
         * Score positively voices with similar locale.
         * @param locale Reference locale. If null, default will be used.
         * @param locale Reference locale.  If null, the system default locale for the
         * current user will be used ({@link Locale#getDefault()}).
         */
        public LanguageMatcher(Locale locale) {
            if (locale == null) {
@@ -149,10 +151,10 @@ public final class RequestConfigHelper {
    }

    /**
     * Get highest quality voice for the default locale.
     * Get highest quality voice for the TTS default locale.
     *
     * Call {@link #highestQuality(EngineStatus, boolean, VoiceScorer)} with
     * {@link LanguageMatcher} set to device default locale.
     * {@link LanguageMatcher} set to the {@link EngineStatus#getDefaultLocale()}.
     *
     * @param engineStatus
     *            Voices status received from a {@link TextToSpeechClient#getEngineStatus()} call.
@@ -164,7 +166,7 @@ public final class RequestConfigHelper {
    public static RequestConfig highestQuality(EngineStatus engineStatus,
            boolean hasToBeEmbedded) {
        return highestQuality(engineStatus, hasToBeEmbedded,
                new LanguageMatcher(Locale.getDefault()));
                new LanguageMatcher(engineStatus.getDefaultLocale()));
    }

}
+1 −3
Original line number Diff line number Diff line
@@ -152,9 +152,7 @@ public final class SynthesisRequestV2 implements Parcelable {
        }
    };

    /**
     * @hide
     */
    /** @hide */
    @Override
    public int describeContents() {
        return 0;
+22 −3
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;

/**
@@ -357,9 +358,13 @@ public class TextToSpeechClient {
        /** Name of the TTS engine package */
        private final String mPackageName;

        private EngineStatus(String packageName, List<VoiceInfo> voices) {
        /** Engine default locale */
        private final Locale mDefaultLocale;

        private EngineStatus(String packageName, List<VoiceInfo> voices, Locale defaultLocale) {
            this.mVoices =  Collections.unmodifiableList(voices);
            this.mPackageName = packageName;
            this.mDefaultLocale = defaultLocale;
        }

        /**
@@ -375,6 +380,16 @@ public class TextToSpeechClient {
        public String getEnginePackage() {
            return mPackageName;
        }

        /**
         * Get the default locale to use for TTS with this TTS engine.
         * Unless the user changed the TTS settings for this engine, the value returned should be
         * the same as the system default locale for the current user
         * ({@link Locale#getDefault()}).
         */
        public Locale getDefaultLocale() {
            return mDefaultLocale;
        }
    }

    /** Unique synthesis request identifier. */
@@ -638,7 +653,9 @@ public class TextToSpeechClient {
            return null;
        }

        return new EngineStatus(mServiceConnection.getEngineName(), voices);
        return new EngineStatus(mServiceConnection.getEngineName(), voices,
                mEnginesHelper.getLocalePrefForEngine(
                        mServiceConnection.getEngineName()));
    }

    private class Connection implements ServiceConnection {
@@ -696,7 +713,9 @@ public class TextToSpeechClient {
            public void onVoicesInfoChange(List<VoiceInfo> voicesInfo) {
                synchronized (mLock) {
                    mEngineStatus = new EngineStatus(mServiceConnection.getEngineName(),
                            voicesInfo);
                            voicesInfo,
                            mEnginesHelper.getLocalePrefForEngine(
                                    mServiceConnection.getEngineName()));
                    mMainHandler.obtainMessage(InternalHandler.WHAT_ENGINE_STATUS_CHANGED,
                            mEngineStatus).sendToTarget();
                }
+2 −2
Original line number Diff line number Diff line
@@ -460,8 +460,8 @@ public abstract class TextToSpeechService extends Service {
    }

    private String[] getSettingsLocale() {
        final String locale = mEngineHelper.getLocalePrefForEngine(mPackageName);
        return TtsEngines.parseLocalePref(locale);
        final Locale locale = mEngineHelper.getLocalePrefForEngine(mPackageName);
        return TtsEngines.toOldLocaleStringFormat(locale);
    }

    private int getSecureSettingInt(String name, int defaultValue) {
Loading