All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twilio.twiml.voice.SsmlPhoneme Maven / Gradle / Ivy

There is a newer version: 10.1.5
Show newest version
/**
 * This code was generated by
 * \ / _    _  _|   _  _
 *  | (_)\/(_)(_|\/| |(/_  v1.0.0
 *       /       /
 */

package com.twilio.twiml.voice;

import com.twilio.twiml.TwiML;

import java.util.HashMap;
import java.util.Map;

/**
 * TwiML wrapper for {@code }
 */
public class SsmlPhoneme extends TwiML {
    public enum Alphabet {
        IPA("ipa"),
        X_SAMPA("x-sampa");

        private final String value;

        private Alphabet(final String value) {
            this.value = value;
        }

        public String toString() {
            return value;
        }
    }

    private final SsmlPhoneme.Alphabet alphabet;
    private final String ph;
    private final String words;

    /**
     * For XML Serialization/Deserialization
     */
    private SsmlPhoneme() {
        this(new Builder((String) null));
    }

    /**
     * Create a new {@code } element
     */
    private SsmlPhoneme(Builder b) {
        super("phoneme", b);
        this.alphabet = b.alphabet;
        this.ph = b.ph;
        this.words = b.words;
    }

    /**
     * The body of the TwiML element
     *
     * @return Element body as a string if present else null
     */
    protected String getElementBody() {
        return this.getWords() == null ? null : this.getWords();
    }

    /**
     * Attributes to set on the generated XML element
     *
     * @return A Map of attribute keys to values
     */
    protected Map getElementAttributes() {
        // Preserve order of attributes
        Map attrs = new HashMap<>();

        if (this.getAlphabet() != null) {
            attrs.put("alphabet", this.getAlphabet().toString());
        }
        if (this.getPh() != null) {
            attrs.put("ph", this.getPh());
        }

        return attrs;
    }

    /**
     * Specify the phonetic alphabet
     *
     * @return Specify the phonetic alphabet
     */
    public SsmlPhoneme.Alphabet getAlphabet() {
        return alphabet;
    }

    /**
     * Specifiy the phonetic symbols for pronunciation
     *
     * @return Specifiy the phonetic symbols for pronunciation
     */
    public String getPh() {
        return ph;
    }

    /**
     * Words to speak
     *
     * @return Words to speak
     */
    public String getWords() {
        return words;
    }

    /**
     * Create a new {@code } element
     */
    public static class Builder extends TwiML.Builder {
        private SsmlPhoneme.Alphabet alphabet;
        private String ph;
        private String words;

        /**
         * Create a {@code } with words
         */
        public Builder(String words) {
            this.words = words;
        }

        /**
         * Specify the phonetic alphabet
         */
        public Builder alphabet(SsmlPhoneme.Alphabet alphabet) {
            this.alphabet = alphabet;
            return this;
        }

        /**
         * Specifiy the phonetic symbols for pronunciation
         */
        public Builder ph(String ph) {
            this.ph = ph;
            return this;
        }

        /**
         * Create and return resulting {@code } element
         */
        public SsmlPhoneme build() {
            return new SsmlPhoneme(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy