Search in sources :

Example 6 with NetworkPolicy

use of com.amplifyframework.predictions.aws.NetworkPolicy in project amplify-android by aws-amplify.

the class SpeechGeneratorConfiguration method fromJson.

/**
 * Construct an instance of {@link SpeechGeneratorConfiguration} from
 * plugin configuration JSON object.
 * @param configurationJson the plugin configuration
 * @return the configuration for speech generation
 * @throws JSONException if convert configuration is malformed
 */
@Nullable
public static SpeechGeneratorConfiguration fromJson(@NonNull JSONObject configurationJson) throws JSONException {
    if (!configurationJson.has(CONFIG_NAME)) {
        return null;
    }
    JSONObject speechGeneratorJson = configurationJson.getJSONObject(CONFIG_NAME);
    String voice = speechGeneratorJson.getString("voice");
    String language = speechGeneratorJson.getString("language");
    String networkPolicyString = speechGeneratorJson.getString("defaultNetworkPolicy");
    final NetworkPolicy networkPolicy = NetworkPolicy.fromKey(networkPolicyString);
    return new SpeechGeneratorConfiguration(voice, language, networkPolicy);
}
Also used : JSONObject(org.json.JSONObject) NetworkPolicy(com.amplifyframework.predictions.aws.NetworkPolicy) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)6 NetworkPolicy (com.amplifyframework.predictions.aws.NetworkPolicy)6 JSONObject (org.json.JSONObject)6 LabelType (com.amplifyframework.predictions.models.LabelType)1 LanguageType (com.amplifyframework.predictions.models.LanguageType)1 TextFormatType (com.amplifyframework.predictions.models.TextFormatType)1 JSONException (org.json.JSONException)1