1
1
package ai .rev .speechtotext ;
2
2
3
3
import ai .rev .helpers .ClientHelper ;
4
- import ai .rev .speechtotext .models .asynchronous .RevAiAccount ;
5
- import ai .rev .speechtotext .models .asynchronous .RevAiCaptionType ;
6
- import ai .rev .speechtotext .models .asynchronous .RevAiJob ;
7
- import ai .rev .speechtotext .models .asynchronous .RevAiJobOptions ;
8
- import ai .rev .speechtotext .models .asynchronous .RevAiTranscript ;
4
+ import ai .rev .speechtotext .models .asynchronous .*;
9
5
import okhttp3 .MediaType ;
10
6
import okhttp3 .MultipartBody ;
11
7
import okhttp3 .OkHttpClient ;
@@ -169,6 +165,33 @@ public RevAiTranscript getTranscriptObject(String id) throws IOException {
169
165
return apiInterface .getTranscriptObject (id ).execute ().body ();
170
166
}
171
167
168
+ /**
169
+ * The method sends a GET request to the /jobs/{id}/transcript/translation/{language} endpoint and returns translated transcript
170
+ * as a String.
171
+ *
172
+ * @param id The ID of the job to return a transcript for.
173
+ * @param language requested transcript language.
174
+ * @return The transcript as a String in text format.
175
+ * @throws IOException If the response has a status code > 399.
176
+ */
177
+ public String getTranslatedTranscriptText (String id ,String language ) throws IOException {
178
+ return apiInterface .getTranslatedTranscriptText (id ,language ).execute ().body ();
179
+ }
180
+
181
+ /**
182
+ * The method sends a GET request to the /jobs/{id}/transcript/translation/{language} endpoint and returns a {@link
183
+ * RevAiTranscript} object containing translated transcript.
184
+ *
185
+ * @param id The ID of the job to return a transcript for.
186
+ * @param language requested transcript language.
187
+ * @return RevAiTranscript The transcript object.
188
+ * @throws IOException If the response has a status code > 399.
189
+ * @see RevAiTranscript
190
+ */
191
+ public RevAiTranscript getTranslatedTranscriptObject (String id , String language ) throws IOException {
192
+ return apiInterface .getTranslatedTranscriptObject (id ,language ).execute ().body ();
193
+ }
194
+
172
195
/**
173
196
* The method sends a GET request to the /jobs/{id}/transcript endpoint and returns the transcript
174
197
* as a String.
@@ -181,6 +204,30 @@ public String getTranscriptText(String id) throws IOException {
181
204
return apiInterface .getTranscriptText (id ).execute ().body ();
182
205
}
183
206
207
+ /**
208
+ * The method sends a GET request to the /jobs/{id}/transcript/summary endpoint and returns the transcript summary
209
+ * as a String.
210
+ *
211
+ * @param id The ID of the job to return a transcript summary for.
212
+ * @return The transcript summary as a String in text format.
213
+ * @throws IOException If the response has a status code > 399.
214
+ */
215
+ public String getTranscriptSummaryText (String id ) throws IOException {
216
+ return apiInterface .getTranscriptSummaryText (id ).execute ().body ();
217
+ }
218
+
219
+ /**
220
+ * The method sends a GET request to the /jobs/{id}/transcript/summary endpoint and returns the transcript summary
221
+ * as a {@link Summary} object.
222
+ *
223
+ * @param id The ID of the job to return a transcript summary for.
224
+ * @return The transcript summary as a String in text format.
225
+ * @throws IOException If the response has a status code > 399.
226
+ */
227
+ public Summary getTranscriptSummaryObject (String id ) throws IOException {
228
+ return apiInterface .getTranscriptSummaryObject (id ).execute ().body ();
229
+ }
230
+
184
231
/**
185
232
* Sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe
186
233
* the media file located at the url provided and returns a {@link RevAiJob} object.
@@ -355,7 +402,7 @@ public RevAiJob submitJobLocalFile(InputStream inputStream, RevAiJobOptions opti
355
402
356
403
/**
357
404
* The method sends a GET request to the /jobs/{id}/captions endpoint and returns captions for the
358
- * provided job ID in the form of an InputStream.
405
+ * provided job ID in the form of an {@link InputStream} .
359
406
*
360
407
* @param id The ID of the job to return captions for.
361
408
* @param captionType An enumeration of the desired caption type. Default is SRT.
@@ -384,6 +431,38 @@ public InputStream getCaptions(String id, RevAiCaptionType captionType, Integer
384
431
return apiInterface .getCaptionText (id , query , contentHeader ).execute ().body ().byteStream ();
385
432
}
386
433
434
+ /**
435
+ * The method sends a GET request to the /jobs/{id}/captions/translation/{language} endpoint and returns translated captions for the
436
+ * provided job ID in the form of an {@link InputStream}.
437
+ *
438
+ * @param id The ID of the job to return captions for.
439
+ * @param language requested translation language.
440
+ * @param captionType An enumeration of the desired caption type. Default is SRT.
441
+ * @param channelId Identifies the audio channel of the file to output captions for. Default is
442
+ * null.
443
+ * @return InputStream A stream of bytes that represents the caption output.
444
+ * @throws IOException If the response has a status code > 399.
445
+ * @throws IllegalArgumentException If the job ID provided is null.
446
+ * @see <a
447
+ * href="https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions">https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions</a>
448
+ */
449
+ public InputStream getTranslatedCaptions (String id , String language , RevAiCaptionType captionType , Integer channelId )
450
+ throws IOException {
451
+ if (id == null ) {
452
+ throw new IllegalArgumentException ("Job ID must be provided" );
453
+ }
454
+ Map <String , String > query = new HashMap <>();
455
+ if (channelId != null ) {
456
+ query .put ("speaker_channel" , channelId .toString ());
457
+ }
458
+ if (captionType == null ) {
459
+ captionType = RevAiCaptionType .SRT ;
460
+ }
461
+ Map <String , String > contentHeader = new HashMap <>();
462
+ contentHeader .put ("Accept" , captionType .getContentType ());
463
+ return apiInterface .getTranslatedCaptionText (id , language , query , contentHeader ).execute ().body ().byteStream ();
464
+ }
465
+
387
466
/**
388
467
* An overload of {@link ApiClient#getCaptions(String, RevAiCaptionType, Integer)} without the
389
468
* optional channel ID.
0 commit comments