Skip to content

Commit 4a97be6

Browse files
authored
REVAI-3854: SuperApi features (#59)
REVAI-3854: SuperApi features
1 parent 770c1df commit 4a97be6

17 files changed

+842
-20
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>org.json</groupId>
4646
<artifactId>json</artifactId>
47-
<version>20190722</version>
47+
<version>20230227</version>
4848
<scope>compile</scope>
4949
</dependency>
5050
<dependency>
@@ -77,7 +77,7 @@
7777
<dependency>
7878
<groupId>com.google.code.gson</groupId>
7979
<artifactId>gson</artifactId>
80-
<version>2.8.6</version>
80+
<version>2.8.9</version>
8181
</dependency>
8282
<dependency>
8383
<groupId>com.squareup.retrofit2</groupId>

src/main/java/ai/rev/speechtotext/ApiClient.java

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package ai.rev.speechtotext;
22

33
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.*;
95
import okhttp3.MediaType;
106
import okhttp3.MultipartBody;
117
import okhttp3.OkHttpClient;
@@ -169,6 +165,33 @@ public RevAiTranscript getTranscriptObject(String id) throws IOException {
169165
return apiInterface.getTranscriptObject(id).execute().body();
170166
}
171167

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+
172195
/**
173196
* The method sends a GET request to the /jobs/{id}/transcript endpoint and returns the transcript
174197
* as a String.
@@ -181,6 +204,30 @@ public String getTranscriptText(String id) throws IOException {
181204
return apiInterface.getTranscriptText(id).execute().body();
182205
}
183206

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+
184231
/**
185232
* Sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe
186233
* 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
355402

356403
/**
357404
* 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}.
359406
*
360407
* @param id The ID of the job to return captions for.
361408
* @param captionType An enumeration of the desired caption type. Default is SRT.
@@ -384,6 +431,38 @@ public InputStream getCaptions(String id, RevAiCaptionType captionType, Integer
384431
return apiInterface.getCaptionText(id, query, contentHeader).execute().body().byteStream();
385432
}
386433

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+
387466
/**
388467
* An overload of {@link ApiClient#getCaptions(String, RevAiCaptionType, Integer)} without the
389468
* optional channel ID.

src/main/java/ai/rev/speechtotext/ApiInterface.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package ai.rev.speechtotext;
22

3-
import ai.rev.speechtotext.models.asynchronous.RevAiAccount;
4-
import ai.rev.speechtotext.models.asynchronous.RevAiJob;
5-
import ai.rev.speechtotext.models.asynchronous.RevAiJobOptions;
6-
import ai.rev.speechtotext.models.asynchronous.RevAiTranscript;
3+
import ai.rev.speechtotext.models.asynchronous.*;
74
import okhttp3.MultipartBody;
85
import okhttp3.ResponseBody;
96
import retrofit2.Call;
@@ -46,6 +43,22 @@ public interface ApiInterface {
4643
@GET("jobs/{id}/transcript")
4744
Call<String> getTranscriptText(@Path("id") String jobID);
4845

46+
@Headers("Accept: " + REV_JSON_CONTENT_TYPE)
47+
@GET("jobs/{id}/transcript/translation/{language}")
48+
Call<RevAiTranscript> getTranslatedTranscriptObject(@Path("id") String jobID, @Path("language") String language);
49+
50+
@Headers("Accept: " + REV_TEXT_CONTENT_TYPE)
51+
@GET("jobs/{id}/transcript/translation/{language}")
52+
Call<String> getTranslatedTranscriptText(@Path("id") String jobID, @Path("language") String language);
53+
54+
@Headers("Accept: " + REV_TEXT_CONTENT_TYPE)
55+
@GET("jobs/{id}/transcript/summary")
56+
Call<String> getTranscriptSummaryText(@Path("id") String jobID);
57+
58+
@Headers("Accept: application/json")
59+
@GET("jobs/{id}/transcript/summary")
60+
Call<Summary> getTranscriptSummaryObject(@Path("id") String jobID);
61+
4962
@POST("jobs")
5063
Call<RevAiJob> submitJobUrl(@Body RevAiJobOptions options);
5164

@@ -62,4 +75,11 @@ Call<ResponseBody> getCaptionText(
6275
@Path("id") String jobID,
6376
@QueryMap Map<String, String> query,
6477
@HeaderMap Map<String, String> contentType);
78+
79+
@GET("jobs/{id}/captions/translation/{language}")
80+
Call<ResponseBody> getTranslatedCaptionText(
81+
@Path("id") String jobID,
82+
@Path("language") String language,
83+
@QueryMap Map<String, String> query,
84+
@HeaderMap Map<String, String> contentType);
6585
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ai.rev.speechtotext.models;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
/** GPT Model type. STANDARD (GPT 3.5) or PREMIUM (GPT 4) */
6+
public enum NlpModel {
7+
8+
/** gpt 3.5. This is the default value. */
9+
@SerializedName("standard")
10+
STANDARD("standard"),
11+
12+
/** gpt 4. */
13+
@SerializedName("premium")
14+
PREMIUM("premium");
15+
16+
private final String model;
17+
18+
NlpModel(String model) {
19+
this.model = model;
20+
}
21+
22+
/**
23+
* Returns the String value of the enumeration.
24+
*
25+
* @return The String value of the enumeration.
26+
*/
27+
public String getModel() { return model; }
28+
29+
@Override
30+
public String toString() {
31+
return "{" + "model='" + model + '\'' + '}';
32+
}
33+
}

src/main/java/ai/rev/speechtotext/models/asynchronous/RevAiJob.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public class RevAiJob {
7979
@SerializedName("segments_to_transcribe")
8080
private List<SegmentToTranscribe> segmentsToTranscribe;
8181

82+
@SerializedName("summarization")
83+
private Summarization summarization;
84+
85+
@SerializedName("translation")
86+
private Translation translation;
87+
8288
/**
8389
* Returns a String that contains the job ID.
8490
*
@@ -517,6 +523,38 @@ public void setSegmentsToTranscribe(List<SegmentToTranscribe> segmentsToTranscri
517523
this.segmentsToTranscribe = segmentsToTranscribe;
518524
}
519525

526+
/**
527+
* Returns summarization options for the job
528+
*
529+
* @return Summarization options for the job
530+
*/
531+
public Summarization getSummarization() {
532+
return summarization;
533+
}
534+
535+
/**
536+
* Sets summarization options for the job
537+
*/
538+
public void setSummarization(Summarization summarization) {
539+
this.summarization = summarization;
540+
}
541+
542+
/**
543+
* Returns translation options for the job
544+
*
545+
* @return Translation options for the job
546+
*/
547+
public Translation getTranslation() {
548+
return translation;
549+
}
550+
551+
/**
552+
* Sets translation options for the job
553+
*/
554+
public void setTranslation(Translation translation) {
555+
this.translation = translation;
556+
}
557+
520558
@Override
521559
public String toString() {
522560
return "{"
@@ -552,7 +590,7 @@ public String toString() {
552590
+ failureDetails
553591
+ '\''
554592
+ ", failure='"
555-
+ failure.getFailureType()
593+
+ getFailureTypeString(failure)
556594
+ '\''
557595
+ ", deleteAfterSeconds='"
558596
+ deleteAfterSeconds
@@ -587,6 +625,18 @@ public String toString() {
587625
+ ", segmentsToTranscribe='"
588626
+ segmentsToTranscribe
589627
+ '\''
628+
+ ", summarization='"
629+
+ summarization
630+
+ '\''
631+
+ ", translation='"
632+
+ translation
633+
+ '\''
590634
+ '}';
591635
}
636+
637+
private static String getFailureTypeString(RevAiFailureType failure) {
638+
if(failure == null)
639+
return "";
640+
return failure.getFailureType();
641+
}
592642
}

src/main/java/ai/rev/speechtotext/models/asynchronous/RevAiJobOptions.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ public class RevAiJobOptions {
136136
@SerializedName("speaker_names")
137137
private List<SpeakerName> speakerNames;
138138

139+
@SerializedName("summarization_config")
140+
private SummarizationOptions summarizationOptions;
141+
142+
@SerializedName("translation_config")
143+
private TranslationOptions translationOptions;
144+
139145
/**
140146
* Returns the media url.
141147
*
@@ -563,4 +569,40 @@ public List<SpeakerName> getSpeakerNames() {
563569
public void setSpeakerNames(List<SpeakerName> speakerNames) {
564570
this.speakerNames = speakerNames;
565571
}
572+
573+
/**
574+
* Returns summarization options
575+
*
576+
* @return Summarization options
577+
*/
578+
public SummarizationOptions getSummarizationOptions() {
579+
return summarizationOptions;
580+
}
581+
582+
/**
583+
* Specifies summarization options.
584+
*
585+
* @param summarizationOptions Summarization options
586+
*/
587+
public void setSummarizationOptions(SummarizationOptions summarizationOptions) {
588+
this.summarizationOptions = summarizationOptions;
589+
}
590+
591+
/**
592+
* Returns translation options.
593+
*
594+
* @return Translation options
595+
*/
596+
public TranslationOptions getTranslationOptions() {
597+
return translationOptions;
598+
}
599+
600+
/**
601+
* Specifies translation options.
602+
*
603+
* @param translationOptions Translation options
604+
*/
605+
public void setTranslationOptions(TranslationOptions translationOptions) {
606+
this.translationOptions = translationOptions;
607+
}
566608
}

0 commit comments

Comments
 (0)