Skip to content

Commit a8ca699

Browse files
authored
REVAI-3854: Usage examples (#62)
* REVAI-3854: Usage examples
1 parent 32f47de commit a8ca699

File tree

4 files changed

+275
-1
lines changed

4 files changed

+275
-1
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ try {
6868
}
6969
RevAiJob revAiJob = apiClient.submitJobLocalFile(fileInputStream, String fileName, RevAiJobOptions options);
7070
```
71+
You can request transcript summary.
72+
```
73+
String urlLinkToFile = "https://www.rev.ai/FTC_Sample_1.mp3";
74+
75+
RevAiJobOptions revAiJobOptions = new RevAiJobOptions();
76+
revAiJobOptions.setSourceConfig(urlLinkToFile, null);
77+
revAiJobOptions.setLanguage("en");
78+
revAiJobOptions.setSummarizationOptions(new SummarizationOptions().setModel(NlpModel.STANDARD));
79+
```
80+
You can request transcript translation into up to five languages.
81+
```
82+
String urlLinkToFile = "https://www.rev.ai/FTC_Sample_1.mp3";
83+
84+
RevAiJobOptions revAiJobOptions = new RevAiJobOptions();
85+
revAiJobOptions.setSourceConfig(urlLinkToFile, null);
86+
revAiJobOptions.setLanguage("en");
87+
revAiJobOptions.setTranslationOptions(new TranslationOptions(Arrays.asList(
88+
new TranslationLanguageOptions("es")
89+
.setModel(NlpModel.PREMIUM),
90+
new TranslationLanguageOptions("de"))
91+
));
92+
```
7193

7294
You can also submit a job to be handled by a human transcriber using our [Human Transcription](https://docs.rev.ai/api/asynchronous/transcribers/#human-transcription) option.
7395
```
@@ -160,6 +182,9 @@ String transcriptText = apiClient.getTranscriptText(revAiJob.getJobId());
160182
161183
// or as an object
162184
RevAiTranscript revAiTranscript = apiClient.getTranscriptObject(revAiJob.getJobId());
185+
186+
// or if you requested transcript translation(s)
187+
RevAiTranscript revAiTranscript = apiClient.getTranslatedTranscriptObject(revAiJob.getJobId(), "es");
163188
```
164189

165190
The text output is a string containing just the text of your transcript. The object form of
@@ -180,8 +205,23 @@ InputStream inputStream = apiClient.getCaptions(revAiJob.getJobId(), RevAiCaptio
180205
// with speaker channels
181206
int channelId = 1;
182207
InputStream inputStream = apiClient.getCaptions(revAiJob.getJobId(), RevAiCaptionType.VTT, channelId);
208+
209+
// or if you requested transcript translation(s)
210+
InputStream inputStream = apiClient.getTranslatedCaptions(revAiJob.getJobId(), "es", RevAiCaptionType.VTT, channelId);
211+
```
212+
213+
### Getting transcript summary
214+
215+
If you requested transcript summary, you can retrieve it as plain text or structured object:
216+
183217
```
218+
// as text
219+
apiClient.getTranscriptSummaryText(job.id);
184220
221+
// as object
222+
apiClient.getTranscriptSummaryObject(job.id);
223+
224+
```
185225
## Streaming Audio
186226

187227
In order to stream audio, you will need to setup a streaming client and the content type
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package ai.rev;
2+
3+
import ai.rev.speechtotext.ApiClient;
4+
import ai.rev.speechtotext.models.NlpModel;
5+
import ai.rev.speechtotext.models.asynchronous.*;
6+
import ai.rev.speechtotext.models.vocabulary.CustomVocabulary;
7+
8+
import java.io.IOException;
9+
import java.io.InputStream;
10+
import java.util.Arrays;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
public class AsyncSummarizeMediaUrl {
15+
16+
public static void main(String[] args) {
17+
// Assign your access token to a String
18+
String accessToken = "<YOUR_ACCESS_TOKEN>";
19+
20+
// Initialize the ApiClient with your access token
21+
ApiClient apiClient = new ApiClient(accessToken);
22+
23+
// Set up source configuration parameters
24+
String mediaUrl = "https://www.rev.ai/FTC_Sample_1.mp3";
25+
26+
// Initialize the RevAiJobOptions object and assign
27+
RevAiJobOptions revAiJobOptions = new RevAiJobOptions();
28+
revAiJobOptions.setSourceConfig(mediaUrl, null);
29+
revAiJobOptions.setDeleteAfterSeconds(2592000); // 30 days in seconds
30+
revAiJobOptions.setLanguage("en");
31+
revAiJobOptions.setSummarizationOptions(new SummarizationOptions().setModel(NlpModel.STANDARD));
32+
33+
RevAiJob submittedJob;
34+
35+
try {
36+
// Submit job with transcription options
37+
submittedJob = apiClient.submitJobUrl(revAiJobOptions);
38+
} catch (IOException e) {
39+
throw new RuntimeException("Failed to submit url [" + mediaUrl + "] " + e.getMessage());
40+
}
41+
String jobId = submittedJob.getJobId();
42+
System.out.println("Job Id: " + jobId);
43+
System.out.println("Job Status: " + submittedJob.getJobStatus());
44+
System.out.println("Created On: " + submittedJob.getCreatedOn());
45+
46+
// Waits 5 seconds between each status check to see if job is complete
47+
boolean isJobComplete = false;
48+
while (!isJobComplete) {
49+
RevAiJob retrievedJob;
50+
try {
51+
retrievedJob = apiClient.getJobDetails(jobId);
52+
} catch (IOException e) {
53+
throw new RuntimeException("Failed to retrieve job [" + jobId + "] " + e.getMessage());
54+
}
55+
56+
RevAiJobStatus retrievedJobStatus = retrievedJob.getJobStatus();
57+
if (retrievedJobStatus == RevAiJobStatus.TRANSCRIBED
58+
|| retrievedJobStatus == RevAiJobStatus.FAILED) {
59+
isJobComplete = true;
60+
} else {
61+
try {
62+
Thread.sleep(5000);
63+
} catch (InterruptedException e) {
64+
e.printStackTrace();
65+
}
66+
}
67+
}
68+
69+
// Waits 5 seconds between each status check to see if summarization job is complete
70+
isJobComplete = false;
71+
while (!isJobComplete) {
72+
RevAiJob retrievedJob;
73+
try {
74+
retrievedJob = apiClient.getJobDetails(jobId);
75+
} catch (IOException e) {
76+
throw new RuntimeException("Failed to retrieve job [" + jobId + "] " + e.getMessage());
77+
}
78+
79+
SummarizationJobStatus summarizationJobStatus = retrievedJob.getSummarization().getJobStatus();
80+
if (summarizationJobStatus == SummarizationJobStatus.COMPLETED
81+
|| summarizationJobStatus == SummarizationJobStatus.FAILED) {
82+
isJobComplete = true;
83+
} else {
84+
try {
85+
Thread.sleep(5000);
86+
} catch (InterruptedException e) {
87+
e.printStackTrace();
88+
}
89+
}
90+
}
91+
92+
// Get the transcript and caption outputs
93+
Summary objectSummary;
94+
String textSummary;
95+
96+
try {
97+
objectSummary = apiClient.getTranscriptSummaryObject(jobId);
98+
textSummary = apiClient.getTranscriptSummaryText(jobId);
99+
100+
System.out.println("Summary:" + textSummary);
101+
} catch (IOException e) {
102+
e.printStackTrace();
103+
}
104+
105+
106+
/*
107+
* The job can now be deleted. Deleting the job will remove ALL information
108+
* about the job from the Rev AI servers. Subsequent requests to Rev AI that
109+
* use the deleted jobs Id will return 404's.
110+
*/
111+
// apiClient.deleteJob(jobId);
112+
}
113+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package ai.rev;
2+
3+
import ai.rev.speechtotext.ApiClient;
4+
import ai.rev.speechtotext.models.NlpModel;
5+
import ai.rev.speechtotext.models.asynchronous.*;
6+
import ai.rev.speechtotext.models.vocabulary.CustomVocabulary;
7+
8+
import java.io.IOException;
9+
import java.io.InputStream;
10+
import java.util.Arrays;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
public class AsyncTranslateMediaUrl {
15+
16+
public static void main(String[] args) {
17+
// Assign your access token to a String
18+
String accessToken = "<YOUR_ACCESS_TOKEN>";
19+
20+
// Initialize the ApiClient with your access token
21+
ApiClient apiClient = new ApiClient(accessToken);
22+
23+
// Set up source configuration parameters
24+
String mediaUrl = "https://www.rev.ai/FTC_Sample_1.mp3";
25+
26+
// Initialize the RevAiJobOptions object and assign
27+
RevAiJobOptions revAiJobOptions = new RevAiJobOptions();
28+
revAiJobOptions.setSourceConfig(mediaUrl, null);
29+
revAiJobOptions.setDeleteAfterSeconds(2592000); // 30 days in seconds
30+
revAiJobOptions.setLanguage("en");
31+
revAiJobOptions.setTranslationOptions(new TranslationOptions(Arrays.asList(
32+
new TranslationLanguageOptions("es")
33+
.setModel(NlpModel.PREMIUM),
34+
new TranslationLanguageOptions("de"))
35+
));
36+
37+
RevAiJob submittedJob;
38+
39+
try {
40+
// Submit job with transcription options
41+
submittedJob = apiClient.submitJobUrl(revAiJobOptions);
42+
} catch (IOException e) {
43+
throw new RuntimeException("Failed to submit url [" + mediaUrl + "] " + e.getMessage());
44+
}
45+
String jobId = submittedJob.getJobId();
46+
System.out.println("Job Id: " + jobId);
47+
System.out.println("Job Status: " + submittedJob.getJobStatus());
48+
System.out.println("Created On: " + submittedJob.getCreatedOn());
49+
50+
// Waits 5 seconds between each status check to see if job is complete
51+
boolean isJobComplete = false;
52+
while (!isJobComplete) {
53+
RevAiJob retrievedJob;
54+
try {
55+
retrievedJob = apiClient.getJobDetails(jobId);
56+
} catch (IOException e) {
57+
throw new RuntimeException("Failed to retrieve job [" + jobId + "] " + e.getMessage());
58+
}
59+
60+
RevAiJobStatus retrievedJobStatus = retrievedJob.getJobStatus();
61+
if (retrievedJobStatus == RevAiJobStatus.TRANSCRIBED
62+
|| retrievedJobStatus == RevAiJobStatus.FAILED) {
63+
isJobComplete = true;
64+
} else {
65+
try {
66+
Thread.sleep(5000);
67+
} catch (InterruptedException e) {
68+
e.printStackTrace();
69+
}
70+
}
71+
}
72+
73+
// Waits 5 seconds between each status check to see if summarization job is complete
74+
isJobComplete = false;
75+
while (!isJobComplete) {
76+
RevAiJob retrievedJob;
77+
try {
78+
retrievedJob = apiClient.getJobDetails(jobId);
79+
} catch (IOException e) {
80+
throw new RuntimeException("Failed to retrieve job [" + jobId + "] " + e.getMessage());
81+
}
82+
83+
TranslationJobStatus translationJobStatus = retrievedJob.getTranslation().getTargetLanguages().get(0).getJobStatus();
84+
if (translationJobStatus == TranslationJobStatus.COMPLETED
85+
|| translationJobStatus == TranslationJobStatus.FAILED) {
86+
isJobComplete = true;
87+
} else {
88+
try {
89+
Thread.sleep(5000);
90+
} catch (InterruptedException e) {
91+
e.printStackTrace();
92+
}
93+
}
94+
}
95+
96+
// Get the transcript and caption outputs
97+
RevAiTranscript objectTranscript;
98+
String textTranscript;
99+
InputStream srtCaptions;
100+
InputStream vttCaptions;
101+
102+
try {
103+
objectTranscript = apiClient.getTranslatedTranscriptObject(jobId, "es");
104+
textTranscript = apiClient.getTranslatedTranscriptText(jobId, "es");
105+
srtCaptions = apiClient.getTranslatedCaptions(jobId, "es", RevAiCaptionType.SRT, null);
106+
vttCaptions = apiClient.getTranslatedCaptions(jobId, "es", RevAiCaptionType.VTT, null);
107+
108+
System.out.println("Translation:" + textTranscript);
109+
} catch (IOException e) {
110+
e.printStackTrace();
111+
}
112+
113+
114+
/*
115+
* The job can now be deleted. Deleting the job will remove ALL information
116+
* about the job from the Rev AI servers. Subsequent requests to Rev AI that
117+
* use the deleted jobs Id will return 404's.
118+
*/
119+
// apiClient.deleteJob(jobId);
120+
}
121+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!-- groupId, artifactId, these namespaces should not be changed -->
66
<groupId>ai.rev</groupId>
77
<artifactId>revai-java-sdk</artifactId>
8-
<version>2.3.2</version>
8+
<version>2.4.0</version>
99
<name>Rev AI SDK for Java</name>
1010
<description>Java SDK for Rev AI API</description>
1111
<url>https://docs.rev.ai/</url>

0 commit comments

Comments
 (0)