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