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

Commit e31ab2d8 authored by Przemyslaw Szczepaniak's avatar Przemyslaw Szczepaniak Committed by Android (Google) Code Review
Browse files

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

parents 53a1eaa7 1b5637ee
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26522,6 +26522,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
@@ -46,7 +46,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) {
@@ -70,7 +71,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) {
@@ -164,10 +166,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.
@@ -179,7 +181,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
@@ -167,9 +167,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