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

Commit 15e71346 authored by Android (Google) Code Review's avatar Android (Google) Code Review Committed by The Android Open Source Project
Browse files

am aa4f1f9e: Merge change 5711 into donut

Merge commit 'aa4f1f9e'

* commit 'aa4f1f9e':
  Adding in TTS service support for language query and level of support.
parents 35a2664f aa4f1f9e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ interface ITts {

    void addSpeechFile(in String text, in String filename);

    String[] getLanguage();

    int isLanguageAvailable(in String language, in String country, in String variant);

    void setLanguage(in String language, in String country, in String variant);

    boolean synthesizeToFile(in String text, in String[] params, in String outputDirectory);
+42 −4
Original line number Diff line number Diff line
@@ -657,18 +657,56 @@ public class TextToSpeech {


    /**
     * Checks if the specified language as represented by the locale is available.
     * Returns a Locale instance describing the language currently being used by the TTS engine.
     * @return language, country (if any) and variant (if any) used by the engine stored in a Locale
     *     instance, or null is the TTS engine has failed.
     */
    public Locale getLanguage() {
        synchronized (mStartLock) {
            if (!mStarted) {
                return null;
            }
            try {
                String[] locStrings =  mITts.getLanguage();
                if (locStrings.length == 3) {
                    return new Locale(locStrings[0], locStrings[1], locStrings[2]);
                } else {
                    return null;
                }
            } catch (RemoteException e) {
                // TTS died; restart it.
                mStarted = false;
                initTts();
            }
            return null;
        }
    }

    /**
     * Checks if the specified language as represented by the Locale is available.
     *
     * @param loc
     *            The locale describing the language to be used.
     *            The Locale describing the language to be used.
     *
     * @return one of TTS_LANG_NOT_SUPPORTED, TTS_LANG_MISSING_DATA, TTS_LANG_AVAILABLE,
     *         TTS_LANG_COUNTRY_AVAILABLE, TTS_LANG_COUNTRY_VAR_AVAILABLE.
     */
    public int isLanguageAvailable(Locale loc) {
        //TODO: Implement isLanguageAvailable
        synchronized (mStartLock) {
            if (!mStarted) {
                return TTS_LANG_NOT_SUPPORTED;
            }
            try {
                return mITts.isLanguageAvailable(loc.getISO3Language(), loc.getISO3Country(),
                        loc.getVariant());
            } catch (RemoteException e) {
                // TTS died; restart it.
                mStarted = false;
                initTts();
            }
            return TTS_LANG_NOT_SUPPORTED;
        }
    }


    /**
+36 −2
Original line number Diff line number Diff line
@@ -148,8 +148,7 @@ public class TtsService extends Service implements OnCompletionListener {


    private void setDefaultSettings() {
        // TODO handle default language
        setLanguage("eng", "USA", "");
        setLanguage(this.getDefaultLanguage(), getDefaultLanguage(), getDefaultLocVariant());

        // speech rate
        setSpeechRate(getDefaultRate());
@@ -218,6 +217,17 @@ public class TtsService extends Service implements OnCompletionListener {
    }


    private int isLanguageAvailable(String lang, String country, String variant) {
        Log.v("TTS", "TtsService.isLanguageAvailable(" + lang + ", " + country + ", " +variant+")");
        return nativeSynth.isLanguageAvailable(lang, country, variant);
    }


    private String[] getLanguage() {
        return nativeSynth.getLanguage();
    }


    private void setLanguage(String lang, String country, String variant) {
        Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
        if (isDefaultEnforced()) {
@@ -892,6 +902,30 @@ public class TtsService extends Service implements OnCompletionListener {
            mSelf.setPitch(pitch);
        }

        /**
         * Returns the level of support for the specified language.
         *
         * @param lang  the three letter ISO language code.
         * @param country  the three letter ISO country code.
         * @param variant  the variant code associated with the country and language pair.
         * @return one of TTS_LANG_NOT_SUPPORTED, TTS_LANG_MISSING_DATA, TTS_LANG_AVAILABLE,
         *      TTS_LANG_COUNTRY_AVAILABLE, TTS_LANG_COUNTRY_VAR_AVAILABLE as defined in
         *      android.speech.tts.TextToSpeech.
         */
        public int isLanguageAvailable(String lang, String country, String variant) {
            return mSelf.isLanguageAvailable(lang, country, variant);
        }

        /**
         * Returns the currently set language / country / variant strings representing the
         * language used by the TTS engine.
         * @return null is no language is set, or an array of 3 string containing respectively
         *      the language, country and variant.
         */
        public String[] getLanguage() {
            return mSelf.getLanguage();
        }

        /**
         * Sets the speech rate for the TTS, which affects the synthesized voice.
         *