001/* 002 * Copyright (c) 2011-2017 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.voice.ncco; 023 024import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 025import com.fasterxml.jackson.annotation.JsonInclude; 026import com.nexmo.client.voice.VoiceName; 027 028/** 029 * An NCCO talk action which allows for synthesized speach to be sent to a call. 030 */ 031@JsonInclude(value = JsonInclude.Include.NON_NULL) 032@JsonIgnoreProperties(ignoreUnknown = true) 033public class TalkAction implements Action { 034 private static final String ACTION = "talk"; 035 036 private String text; 037 private Boolean bargeIn; 038 private Integer loop; 039 private Float level; 040 private VoiceName voiceName; 041 042 private TalkAction(Builder builder) { 043 this.text = builder.text; 044 this.bargeIn = builder.bargeIn; 045 this.loop = builder.loop; 046 this.level = builder.level; 047 this.voiceName = builder.voiceName; 048 } 049 050 @Override 051 public String getAction() { 052 return ACTION; 053 } 054 055 public String getText() { 056 return text; 057 } 058 059 public Boolean getBargeIn() { 060 return bargeIn; 061 } 062 063 public Integer getLoop() { 064 return loop; 065 } 066 067 public Float getLevel() { 068 return level; 069 } 070 071 public VoiceName getVoiceName() { 072 return voiceName; 073 } 074 075 public static Builder builder(String text) { 076 return new Builder(text); 077 } 078 079 public static class Builder { 080 private String text; 081 private Boolean bargeIn = null; 082 private Integer loop = null; 083 private Float level = null; 084 private VoiceName voiceName = null; 085 086 /** 087 * @param text A string of up to 1,500 characters (excluding SSML tags) containing the message to be 088 * synthesized in the Call or Conversation. A single comma in text adds a short pause to the 089 * synthesized speech. To add a longer pause a break tag needs to be used in SSML. 090 * <p> 091 * To use SSML tags, you must enclose the text in a speak element. 092 */ 093 public Builder(String text) { 094 this.text = text; 095 } 096 097 /** 098 * @param text A string of up to 1,500 characters (excluding SSML tags) containing the message to be 099 * synthesized in the Call or Conversation. A single comma in text adds a short pause to the 100 * synthesized speech. To add a longer pause a break tag needs to be used in SSML. 101 * <p> 102 * To use SSML tags, you must enclose the text in a speak element. 103 * 104 * @return The {@link Builder} to keep building. 105 */ 106 public Builder text(String text) { 107 this.text = text; 108 return this; 109 } 110 111 /** 112 * @param bargeIn Set to true so this action is terminated when the user presses a button on the keypad. 113 * Use this feature to enable users to choose an option without having to listen to the whole 114 * message in your Interactive Voice Response (IVR). If you set bargeIn to true the next 115 * action in the NCCO stack must be an input action. The default value is false. 116 * 117 * @return The {@link Builder} to keep building. 118 */ 119 public Builder bargeIn(Boolean bargeIn) { 120 this.bargeIn = bargeIn; 121 return this; 122 } 123 124 /** 125 * @param loop The number of times text is repeated before the Call is closed. 126 * The default value is 1. Set to 0 to loop infinitely. 127 * 128 * @return The {@link Builder} to keep building. 129 */ 130 public Builder loop(Integer loop) { 131 this.loop = loop; 132 return this; 133 } 134 135 /** 136 * @param level The volume level that the speech is played. This can be any value between -1 to 1 with 0 137 * being the default. 138 * 139 * @return The {@link Builder} to keep building. 140 */ 141 public Builder level(Float level) { 142 this.level = level; 143 return this; 144 } 145 146 /** 147 * @param voiceName The name of the voice used to deliver text. You use the voiceName that has the correct 148 * language, gender and accent for the message you are sending. 149 * <p> 150 * For example, the default 151 * voice {@link VoiceName#KIMBERLY} is a female who speaks English with an American accent (en-US). 152 * 153 * @return The {@link Builder} to keep building. 154 */ 155 public Builder voiceName(VoiceName voiceName) { 156 this.voiceName = voiceName; 157 return this; 158 } 159 160 /** 161 * @return A new {@link TalkAction} object from the stored builder options. 162 */ 163 public TalkAction build() { 164 return new TalkAction(this); 165 } 166 } 167}