001/*
002 *   Copyright 2024 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.conversations;
017
018import com.fasterxml.jackson.annotation.JsonIgnore;
019import com.vonage.client.voice.TextToSpeechLanguage;
020
021/**
022 * Represents an {@link EventType#AUDIO_RECORD} event.
023 */
024public final class AudioRecordEvent extends EventWithBody<AudioRecordEventBody> {
025
026    AudioRecordEvent() {}
027
028    private AudioRecordEvent(Builder builder) {
029        super(builder);
030        body = new AudioRecordEventBody(builder);
031    }
032
033    /**
034     * Text-to-speech transcription language.
035     *
036     * @return The transcription language as an enum, or {@code null} if unspecified.
037     */
038    @JsonIgnore
039    public TextToSpeechLanguage getLanguage() {
040        return body.transcription != null ? body.transcription.language : null;
041    }
042
043    /**
044     * Whether sentiment analysis is enabled.
045     *
046     * @return {@code true} if sentiment analysis is enabled,
047     * or {@code null} if transcription is not enabled.
048     */
049    @JsonIgnore
050    public Boolean getSentimentAnalysis() {
051        return body.transcription != null ? body.transcription.sentimentAnalysis : null;
052    }
053
054    /**
055     * File format for the recording.
056     *
057     * @return The recording format as a string, or {@code null} if unspecified.
058     */
059    @JsonIgnore
060    public String getFormat() {
061        return body.format;
062    }
063
064    /**
065     * The validity parameter.
066     *
067     * @return The validity as an integer, or {@code null} if unspecified.
068     */
069    @JsonIgnore
070    public Integer getValidity() {
071        return body.validity;
072    }
073
074    /**
075     * Number of channels for the recording.
076     *
077     * @return The number of channels as an Integer, or {@code null} if unspecified.
078     */
079    @JsonIgnore
080    public Integer getChannels() {
081        return body.channels;
082    }
083
084    /**
085     * Whether the audio recording is streamed.
086     *
087     * @return {@code true} if the recording is streamed, or {@code null} if unspecified.
088     */
089    @JsonIgnore
090    public Boolean getStreamed() {
091        return body.streamed;
092    }
093
094    /**
095     * Whether the audio is split.
096     *
097     * @return {@code true} if the recording is split, or {@code null} if unspecified.
098     */
099    @JsonIgnore
100    public Boolean getSplit() {
101        return body.split;
102    }
103
104    /**
105     * Whether the audio has multiple tracks.
106     *
107     * @return {@code true} if the recording is multi-track, or {@code null} if unspecified.
108     */
109    @JsonIgnore
110    public Boolean getMultitrack() {
111        return body.multitrack;
112    }
113
114    /**
115     * Whether to detect speech in the recording.
116     *
117     * @return {@code true} if speech detection is enabled, or {@code null} if unspecified.
118     */
119    @JsonIgnore
120    public Boolean getDetectSpeech() {
121        return body.detectSpeech;
122    }
123
124    /**
125     * Whether to enable beep start.
126     *
127     * @return {@code true} if beep start, or {@code null} if unspecified.
128     */
129    @JsonIgnore
130    public Boolean getBeepStart() {
131        return body.beepStart;
132    }
133
134    /**
135     * Whether to enable beep stop.
136     *
137     * @return {@code true} if beep stop, or {@code null} if unspecified.
138     */
139    @JsonIgnore
140    public Boolean getBeepStop() {
141        return body.beepStop;
142    }
143
144    /**
145     * Entry point for constructing an instance of this class.
146     *
147     * @return A new Builder.
148     */
149    public static Builder builder() {
150        return new Builder();
151    }
152
153    /**
154     * Builder for setting the Audio Record event parameters.
155     */
156    public static final class Builder extends EventWithBody.Builder<AudioRecordEvent, Builder> {
157        String format;
158        Integer validity, channels;
159        Boolean streamed, split, multitrack, detectSpeech, beepStart, beepStop, sentimentAnalysis;
160        TextToSpeechLanguage language;
161
162        Builder() {
163            super(EventType.AUDIO_RECORD);
164        }
165
166        /**
167         * File format for the recording.
168         *
169         * @param format The format as a string.
170         *
171         * @return This builder.
172         */
173        public Builder format(String format) {
174            this.format = format;
175            return this;
176        }
177
178        /**
179         * Audio recording validity parameter.
180         *
181         * @param validity The validity as an int.
182         *
183         * @return This builder.
184         */
185        public Builder validity(int validity) {
186            this.validity = validity;
187            return this;
188        }
189
190        /**
191         * Number of channels for the recording.
192         *
193         * @param channels The number of channels as an int.
194         *
195         * @return This builder.
196         */
197        public Builder channels(int channels) {
198            this.channels = channels;
199            return this;
200        }
201
202        /**
203         * Whether the audio recording is streamed.
204         *
205         * @param streamed {@code true} if the recording should be streamed.
206         *
207         * @return This builder.
208         */
209        public Builder streamed(boolean streamed) {
210            this.streamed = streamed;
211            return this;
212        }
213
214        /**
215         * Whether the recording should be split.
216         *
217         * @param split {@code true} if the audio should be split.
218         *
219         * @return This builder.
220         */
221        public Builder split(boolean split) {
222            this.split = split;
223            return this;
224        }
225
226        /**
227         * Whether the audio should have multiple tracks.
228         *
229         * @param multitrack {@code true} if the recording should be multi-track.
230         *
231         * @return This builder.
232         */
233        public Builder multitrack(boolean multitrack) {
234            this.multitrack = multitrack;
235            return this;
236        }
237
238        /**
239         * Whether speech detection is enabled.
240         *
241         * @param detectSpeech {@code true} to enable speech detection.
242         *
243         * @return This builder.
244         */
245        public Builder detectSpeech(boolean detectSpeech) {
246            this.detectSpeech = detectSpeech;
247            return this;
248        }
249
250        /**
251         * Whether to set the {@code beep_start} flag.
252         *
253         * @param beepStart {@code true} to enable beep start.
254         *
255         * @return This builder.
256         */
257        public Builder beepStart(boolean beepStart) {
258            this.beepStart = beepStart;
259            return this;
260        }
261
262        /**
263         * Whether to set the {@code beep_stop} flag.
264         *
265         * @param beepStop {@code true} to enable beep stop.
266         *
267         * @return This builder.
268         */
269        public Builder beepStop(boolean beepStop) {
270            this.beepStop = beepStop;
271            return this;
272        }
273
274        /**
275         * Whether to enable sentiment analysis in the recording transcription.
276         *
277         * @param sentimentAnalysis {@code true} to enable transcription sentiment analysis.
278         *
279         * @return This builder.
280         */
281        public Builder sentimentAnalysis(boolean sentimentAnalysis) {
282            this.sentimentAnalysis = sentimentAnalysis;
283            return this;
284        }
285
286        /**
287         * Text-to-speech transcription language. Setting this will enable recording transcription.
288         *
289         * @param language The transcription language as an enum.
290         *
291         * @return This builder.
292         */
293        public Builder language(TextToSpeechLanguage language) {
294            this.language = language;
295            return this;
296        }
297
298        @Override
299        public AudioRecordEvent build() {
300            return new AudioRecordEvent(this);
301        }
302    }
303}