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.core.JsonProcessingException; 019import com.fasterxml.jackson.databind.ObjectMapper; 020import com.vonage.client.VonageUnexpectedException; 021 022/** 023 * The request object to send synthesized audio. 024 * <p> 025 * Contains the {@code uuid} of the {@link Call} and the {@link TalkPayload} to be sent in the request. 026 */ 027 028public class TalkRequest { 029 private TalkPayload talkPayload; 030 private String uuid; 031 032 public TalkRequest(String uuid, String text, VoiceName voiceName, int loop) { 033 this.talkPayload = new TalkPayload(text, voiceName, loop); 034 this.uuid = uuid; 035 } 036 037 public TalkRequest(String uuid, String text, VoiceName voiceName) { 038 this(uuid, text, voiceName, 1); 039 } 040 041 public TalkRequest(String uuid, String text, int loop) { 042 this(uuid, text, VoiceName.KIMBERLY, loop); 043 } 044 045 public TalkRequest(String uuid, String text) { 046 this(uuid, text, VoiceName.KIMBERLY, 1); 047 } 048 049 public String getUuid() { 050 return uuid; 051 } 052 053 public void setUuid(String uuid) { 054 this.uuid = uuid; 055 } 056 057 public String toJson() { 058 try { 059 ObjectMapper mapper = new ObjectMapper(); 060 return mapper.writeValueAsString(this.talkPayload); 061 } catch (JsonProcessingException jpe) { 062 throw new VonageUnexpectedException("Failed to produce json from TalkRequest object.", jpe); 063 } 064 } 065}