001/* 002 * Copyright 2020 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.voice; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.fasterxml.jackson.core.JsonProcessingException; 020import com.fasterxml.jackson.databind.ObjectMapper; 021import com.vonage.client.VonageUnexpectedException; 022 023/** 024 * The JSON payload that will be sent in a {@link TalkRequest}. 025 * <p> 026 * {@code text}: A string of up to 1500 characters containing the message to be synthesized 027 * in the Call or Conversation. Each comma in text adds a short pause to the synthesized speech. 028 * {@link VoiceName}: The name of the voice used to deliver {@code text}. 029 * {@code loop}: The number of times the audio file at stream_url is repeated before the stream ends. Set to 0 to loop infinitely. 030 */ 031 032public class TalkPayload { 033 private String text; 034 private VoiceName voiceName; 035 private int loop; 036 037 public TalkPayload(String text, VoiceName voiceName, int loop) { 038 this.text = text; 039 this.voiceName = voiceName; 040 this.loop = loop; 041 } 042 043 public int getLoop() { 044 return loop; 045 } 046 047 public String getText() { 048 return text; 049 } 050 051 @JsonProperty("voice_name") 052 public VoiceName getVoiceName() { 053 return voiceName; 054 } 055 056 public String toJson() { 057 try { 058 ObjectMapper mapper = new ObjectMapper(); 059 return mapper.writeValueAsString(this); 060 } catch (JsonProcessingException jpe) { 061 throw new VonageUnexpectedException("Failed to produce json from TalkPayload object.", jpe); 062 } 063 } 064}