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

Commit b65dba45 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 5470 into donut

* changes:
  Use the same interface in the TTS engine interface for setLanguage and loadLanguage. Adding function to check the support level for a language in TTS engine interface.
parents aae628b4 d6d03e05
Loading
Loading
Loading
Loading
+31 −10
Original line number Original line Diff line number Diff line
@@ -69,6 +69,14 @@ enum tts_result {
    TTS_MISSING_RESOURCES       = -6
    TTS_MISSING_RESOURCES       = -6
};
};


enum tts_support_result {
    TTS_LANG_COUNTRY_VAR_AVAILABLE = 2,
    TTS_LANG_COUNTRY_AVAILABLE = 1,
    TTS_LANG_AVAILABLE = 0,
    TTS_LANG_MISSING_DATA = -1,
    TTS_LANG_NOT_SUPPORTED = -2
};

class TtsEngine
class TtsEngine
{
{
public:
public:
@@ -86,19 +94,32 @@ public:
    // @return TTS_SUCCESS, or TTS_FAILURE
    // @return TTS_SUCCESS, or TTS_FAILURE
    virtual tts_result stop();
    virtual tts_result stop();


    // Returns the level of support for the language, country and variant.
    // @return TTS_LANG_COUNTRY_VAR_AVAILABLE if the language, country and variant are supported,
    //            and the corresponding resources are correctly installed
    //         TTS_LANG_COUNTRY_AVAILABLE if the language and country are supported and the
    //             corresponding resources are correctly installed, but there is no match for
    //             the specified variant
    //         TTS_LANG_AVAILABLE if the language is supported and the
    //             corresponding resources are correctly installed, but there is no match for
    //             the specified country and variant
    //         TTS_LANG_MISSING_DATA if the required resources to provide any level of support
    //             for the language are not correctly installed
    //         TTS_LANG_NOT_SUPPORTED if the language is not supported by the TTS engine.
    virtual tts_support_result isLanguageAvailable(const char *lang, const char *country,
            const char *variant);

    // Load the resources associated with the specified language. The loaded
    // Load the resources associated with the specified language. The loaded
    // language will only be used once a call to setLanguage() with the same
    // language will only be used once a call to setLanguage() with the same
    // language value is issued. Language values are based on the Android
    // language value is issued. Language and country values are coded according to the ISO three
    // conventions for localization as described in the Android platform
    // letter codes for languages and countries, as can be retrieved from a java.util.Locale
    // documentation on internationalization. This implies that language
    // instance. The variant value is encoded as the variant string retrieved from a
    // data is specified in the format xx-rYY, where xx is a two letter
    // java.util.Locale instance built with that variant data.
    // ISO 639-1 language code in lowercase and rYY is a two letter
    // @param lang pointer to the ISO three letter code for the language
    // ISO 3166-1-alpha-2 language code in uppercase preceded by a
    // @param country pointer to the ISO three letter code for the country
    // lowercase "r".
    // @param variant pointer to the variant code
    // @param value pointer to the language value
    // @param size  length of the language value
    // @return TTS_SUCCESS, or TTS_FAILURE
    // @return TTS_SUCCESS, or TTS_FAILURE
    virtual tts_result loadLanguage(const char *value, const size_t size);
    virtual tts_result loadLanguage(const char *lang, const char *country, const char *variant);
    
    
    // Load the resources associated with the specified language, country and Locale variant.
    // Load the resources associated with the specified language, country and Locale variant.
    // The loaded language will only be used once a call to setLanguageFromLocale() with the same
    // The loaded language will only be used once a call to setLanguageFromLocale() with the same
+30 −2
Original line number Original line Diff line number Diff line
@@ -297,8 +297,32 @@ android_tts_SynthProxy_setLanguage(JNIEnv *env, jobject thiz, jint jniData,
                variantNativeString);
                variantNativeString);
    }
    }
    env->ReleaseStringUTFChars(language, langNativeString);
    env->ReleaseStringUTFChars(language, langNativeString);
    env->ReleaseStringUTFChars(language, countryNativeString);
    env->ReleaseStringUTFChars(country, countryNativeString);
    env->ReleaseStringUTFChars(language, variantNativeString);
    env->ReleaseStringUTFChars(variant, variantNativeString);
}


static void
android_tts_SynthProxy_loadLanguage(JNIEnv *env, jobject thiz, jint jniData,
        jstring language, jstring country, jstring variant)
{
    if (jniData == 0) {
        LOGE("android_tts_SynthProxy_loadLanguage(): invalid JNI data");
        return;
    }

    SynthProxyJniStorage* pSynthData = (SynthProxyJniStorage*)jniData;
    const char *langNativeString = env->GetStringUTFChars(language, 0);
    const char *countryNativeString = env->GetStringUTFChars(country, 0);
    const char *variantNativeString = env->GetStringUTFChars(variant, 0);
    // TODO check return codes
    if (pSynthData->mNativeSynthInterface) {
        pSynthData->mNativeSynthInterface->loadLanguage(langNativeString, countryNativeString,
                variantNativeString);
    }
    env->ReleaseStringUTFChars(language, langNativeString);
    env->ReleaseStringUTFChars(country, countryNativeString);
    env->ReleaseStringUTFChars(variant, variantNativeString);
}
}




@@ -567,6 +591,10 @@ static JNINativeMethod gMethods[] = {
        "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
        "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
        (void*)android_tts_SynthProxy_setLanguage
        (void*)android_tts_SynthProxy_setLanguage
    },
    },
    {   "native_loadLanguage",
        "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
        (void*)android_tts_SynthProxy_loadLanguage
    },
    {   "native_setSpeechRate",
    {   "native_setSpeechRate",
        "(II)V",
        "(II)V",
        (void*)android_tts_SynthProxy_setSpeechRate
        (void*)android_tts_SynthProxy_setSpeechRate
+10 −0
Original line number Original line Diff line number Diff line
@@ -74,6 +74,13 @@ public class SynthProxy {
        native_setLanguage(mJniData, language, country, variant);
        native_setLanguage(mJniData, language, country, variant);
    }
    }
    
    
    /**
     * Loads the language: it's not set, but prepared for use later.
     */
    public void loadLanguage(String language, String country, String variant) {
        native_loadLanguage(mJniData, language, country, variant);
    }

    /**
    /**
     * Sets the speech rate
     * Sets the speech rate
     */
     */
@@ -150,6 +157,9 @@ public class SynthProxy {
    private native final void native_setLanguage(int jniData, String language, String country,
    private native final void native_setLanguage(int jniData, String language, String country,
            String variant);
            String variant);
    
    
    private native final void native_loadLanguage(int jniData, String language, String country,
            String variant);

    private native final void native_setSpeechRate(int jniData, int speechRate);
    private native final void native_setSpeechRate(int jniData, int speechRate);
    
    
    private native final void native_setPitch(int jniData, int speechRate);
    private native final void native_setPitch(int jniData, int speechRate);