001package com.plivo.examples;
002
003import com.plivo.api.exceptions.PlivoValidationException;
004import com.plivo.api.exceptions.PlivoXmlException;
005import com.plivo.api.xml.Response;
006import com.plivo.api.xml.Speak;
007
008public class SSML {
009
010        public static void main(String[] args) throws Exception {
011                validateSSMLInvalidLanguage();
012        }
013
014        public static void validateEmptyVoiceWithSSML() {
015                Response response;
016                try {
017                        response = new Response().children(
018                                        new Speak("validate speak")
019            .language("en-US")
020            .loop(0)
021                                        .addBreak("maximum", "250ms"));
022                        System.out.println(response.toXmlString());
023                } catch (PlivoXmlException | PlivoValidationException e) {
024                        // TODO Auto-generated catch block
025                        e.printStackTrace();
026                }
027
028        }
029
030        public static void validateManOrWomenVoiceWithSSML() {
031                Response response;
032                try {
033                        response = new Response().children(
034                                        new Speak("validate speak")
035            .voice("MAN")
036            .language("en-US")
037            .loop(0)
038                                        .addBreak("maximum", "250ms"));
039                        System.out.println(response.toXmlString());
040                } catch (PlivoXmlException | PlivoValidationException e) {
041                        // TODO Auto-generated catch block
042                        e.printStackTrace();
043                }
044
045        }
046
047        public static void validateSpeakWithDefaultManOrWomenVoiceWithoutSSML() {
048                Response response;
049                try {
050                        response = new Response().children(
051                                        new Speak("validate speak")
052            .voice("MAN")
053            .language("en-US")
054            .loop(0));
055                        System.out.println(response.toXmlString());
056                } catch (PlivoXmlException | PlivoValidationException e) {
057                        // TODO Auto-generated catch block
058                        e.printStackTrace();
059                }
060
061        }
062
063        public static void validateSpeakCharlimit() {
064                Response response;
065                try {
066                        response = new Response().children(
067                                        new Speak(getAlphaNumericString(3330))
068            .voice("MAN")
069            .language("en-US")
070            .loop(0));
071                        System.out.println(response.toXmlString());
072                } catch (PlivoXmlException | PlivoValidationException e) {
073                        // TODO Auto-generated catch block
074                        e.printStackTrace();
075                }
076        }
077        
078        public static void validateBasicSSML() {
079                try {
080                        Response response = new Response().children(
081                                        new Speak("validate speak")
082            .voice("Polly.Salli")
083            .language("en-US")
084            .loop(0)
085                                        .addBreak("maximum", "250ms")
086                                        .continueSpeak("Continue speak test 1.")
087                                        .addEmphasis("sdfghjjhd", "maximum")
088                                        .addLang("LANG LANG", "maximum")
089                                        .continueSpeak("THIS IS A TEST.")
090                                        );
091
092                        System.out.println(response.toXmlString());
093                } catch (PlivoXmlException | PlivoValidationException e) {
094                        // TODO Auto-generated catch block
095                        e.printStackTrace();
096                }
097        }
098        
099        public static void validateSSMLVoiceLength() {
100                try {
101                        Response response = new Response().children(
102                                        new Speak("validate speak")
103            .voice("Polly.Salli")
104            .language("en-US")
105            .loop(0)
106                                        .addBreak("maximum", "250ms")
107                                        .continueSpeak("Continue speak test 1.")
108                                        .addEmphasis("sdfghjjhd", "maximum")
109                                        .addLang("LANG LANG", "maximum")
110                                        .continueSpeak("THIS IS A TEST.")
111                                        );
112
113                        System.out.println(response.toXmlString());
114                } catch (PlivoXmlException | PlivoValidationException e) {
115                        // TODO Auto-generated catch block
116                        e.printStackTrace();
117                }
118        }
119        
120        public static void validateSSMLInvalidLanguage() {
121                try {
122                        Response response = new Response().children(
123                                        new Speak("validate speak")
124            .voice("Polly.Salli")
125            .language("en-US")
126            .loop(0)
127                                        .addBreak("maximum", "250ms")
128                                        .continueSpeak("Continue speak test 1.")
129                                        .addEmphasis("sdfghjjhd", "maximum")
130                                        .addLang("LANG LANG", "maximum")
131                                        .continueSpeak("THIS IS A TEST.")
132                                        );
133
134                        System.out.println(response.toXmlString());
135                } catch (PlivoXmlException | PlivoValidationException e) {
136                        // TODO Auto-generated catch block
137                        e.printStackTrace();
138                }
139        }
140
141        public  static String getAlphaNumericString(int n) 
142        { 
143                String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
144                                + "0123456789"
145                                + "abcdefghijklmnopqrstuvxyz";  
146                StringBuilder sb = new StringBuilder(n); 
147                for (int i = 0; i < n; i++) { 
148                        int index 
149                        = (int)(AlphaNumericString.length() 
150                                        * Math.random());  
151                        sb.append(AlphaNumericString 
152                                        .charAt(index)); 
153                } 
154
155                return sb.toString(); 
156        }
157
158
159}
160