Skip to content

Commit 59e988d

Browse files
AISDK-190 Update sdks to support notification_config and source_config (#42)
1 parent 8ff7fa4 commit 59e988d

File tree

14 files changed

+333
-69
lines changed

14 files changed

+333
-69
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ See the [API docs](https://docs.rev.ai) for more information about the API.
1111
The recommended way to use the Rev AI Java SDK is to import it into the project using Maven.
1212

1313
<dependency>
14-
<groupId>ai.rev.speechtotext</groupId>
15-
<artifactId>revai-java-sdk-speechtotext</artifactId>
16-
<version>1.4.0</version>
14+
<groupId>ai.rev</groupId>
15+
<artifactId>revai-java-sdk</artifactId>
16+
<version>2.1.0</version>
1717
</dependency>
1818

1919
## Build and install locally from source
2020
Once you've cloned the repo you can use Maven to build it locally and install it in your local Maven .m2 repository.
2121

22-
mvn install -Dmaven.test.skip=true
22+
mvn install -DskipTests=true
2323

2424
## Support
2525

@@ -95,9 +95,14 @@ RevAiJob revAiJob = apiClient.submitJobUrl(urlLinkToFile, options);
9595

9696
If you want to get fancy, all submit job methods have overrides that allow specifying
9797
[RevAiJobOptions](src/main/java/ai/rev/speechtotext/models/asynchronous/RevAiJobOptions.java) to configure job specific settings.
98-
In RevAiJobOptions, you could include `metadata`, `callback_url`,
99-
`skip_diarization`, `skip_punctuation`, `speaker_channels_count`, `custom_vocabularies`, `filter_profanity`, `remove_disfluencies`, `delete_after_seconds` and `language` as optional parameters, these are described in the request body of
100-
the [Submit Job](https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob) endpoint.
98+
In RevAiJobOptions, you could include `metadata`,`notification_config`,
99+
`skip_diarization`, `skip_punctuation`, `speaker_channels_count`,`custom_vocabularies`,
100+
`filter_profanity`, `remove_disfluencies`, `delete_after_seconds`, and `language` as optional parameters.
101+
102+
The url submission option also supports authentication headers by using the `source_config` option.
103+
104+
All options are described in the request body of the
105+
[Submit Job](https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob) endpoint.
101106

102107
### Checking your job's status
103108

examples/AsyncTranscribeLocalMediaFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ai.rev;
22

3+
import ai.rev.speechtotext.ApiClient;
34
import ai.rev.speechtotext.models.asynchronous.RevAiCaptionType;
45
import ai.rev.speechtotext.models.asynchronous.RevAiJob;
56
import ai.rev.speechtotext.models.asynchronous.RevAiJobOptions;
@@ -28,7 +29,7 @@ public static void main(String[] args) {
2829
RevAiJobOptions revAiJobOptions = new RevAiJobOptions();
2930
revAiJobOptions.setCustomVocabularies(Arrays.asList(customVocabulary));
3031
revAiJobOptions.setMetadata("My first submission");
31-
revAiJobOptions.setCallbackUrl("https://example.com");
32+
revAiJobOptions.setNotificationConfig("https://example.com");
3233
revAiJobOptions.setSkipPunctuation(false);
3334
revAiJobOptions.setSkipDiarization(false);
3435
revAiJobOptions.setFilterProfanity(true);

examples/AsyncTranscribeMediaUrl.java

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

3+
import ai.rev.speechtotext.ApiClient;
34
import ai.rev.speechtotext.models.asynchronous.RevAiCaptionType;
45
import ai.rev.speechtotext.models.asynchronous.RevAiJob;
56
import ai.rev.speechtotext.models.asynchronous.RevAiJobOptions;
@@ -10,6 +11,8 @@
1011
import java.io.IOException;
1112
import java.io.InputStream;
1213
import java.util.Arrays;
14+
import java.util.HashMap;
15+
import java.util.Map;
1316

1417
public class AsyncTranscribeMediaUrl {
1518

@@ -24,11 +27,24 @@ public static void main(String[] args) {
2427
CustomVocabulary customVocabulary =
2528
new CustomVocabulary(Arrays.asList("Robert Berwick", "Noam Chomsky", "Evelina Fedorenko"));
2629

30+
// Set up source configuration parameters
31+
String mediaUrl = "https://www.rev.ai/FTC_Sample_1.mp3";
32+
// Authorization header is optional; use it if needed to access the source media url
33+
Map<String, String> sourceAuth = new HashMap<>();
34+
sourceAuth.put("Authorization", "Bearer <source_token>");
35+
36+
// Set up notification configuration parameters
37+
String callbackUrl = "https://example.com";
38+
// Authorization header is optional; use it if needed to access the callback url
39+
Map<String, String> notificationAuth = new HashMap<>();
40+
notificationAuth.put("Authorization", "Bearer <notification_token>");
41+
2742
// Initialize the RevAiJobOptions object and assign
2843
RevAiJobOptions revAiJobOptions = new RevAiJobOptions();
44+
revAiJobOptions.setSourceConfig(mediaUrl, sourceAuth);
2945
revAiJobOptions.setCustomVocabularies(Arrays.asList(customVocabulary));
3046
revAiJobOptions.setMetadata("My first submission");
31-
revAiJobOptions.setCallbackUrl("https://example.com");
47+
revAiJobOptions.setNotificationConfig(callbackUrl, notificationAuth);
3248
revAiJobOptions.setSkipPunctuation(false);
3349
revAiJobOptions.setSkipDiarization(false);
3450
revAiJobOptions.setFilterProfanity(true);
@@ -40,11 +56,9 @@ public static void main(String[] args) {
4056

4157
RevAiJob submittedJob;
4258

43-
String mediaUrl = "https://www.rev.ai/FTC_Sample_1.mp3";
44-
4559
try {
46-
// Submit the local file and transcription options
47-
submittedJob = apiClient.submitJobUrl(mediaUrl, revAiJobOptions);
60+
// Submit job with transcription options
61+
submittedJob = apiClient.submitJobUrl(revAiJobOptions);
4862
} catch (IOException e) {
4963
throw new RuntimeException("Failed to submit url [" + mediaUrl + "] " + e.getMessage());
5064
}

examples/CustomVocabularies.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
package ai.rev;
2-
1+
import ai.rev.speechtotext.CustomVocabulariesClient;
32
import ai.rev.speechtotext.models.vocabulary.CustomVocabulary;
43
import ai.rev.speechtotext.models.vocabulary.CustomVocabularyInformation;
54
import ai.rev.speechtotext.models.vocabulary.CustomVocabularyStatus;
65
import ai.rev.speechtotext.models.vocabulary.CustomVocabularySubmission;
76

87
import java.io.IOException;
98
import java.util.Arrays;
9+
import java.util.HashMap;
10+
import java.util.Map;
1011

1112
public class CustomVocabularies {
1213

@@ -21,16 +22,21 @@ public static void main(String[] args) {
2122
CustomVocabulary customVocabulary =
2223
new CustomVocabulary(Arrays.asList("Robert Berwick", "Noam Chomsky", "Evelina Fedorenko"));
2324

25+
// Set up the notification url if desired
26+
String notificationUrl = "https://example.com";
27+
// Authorization header is optional; use it if needed to access the callback notification url
28+
Map<String, String> notificationAuth = new HashMap<>();
29+
notificationAuth.put("Authorization", "Bearer <callback_token>");
30+
2431
CustomVocabularySubmission customVocabularySubmission = new CustomVocabularySubmission();
2532
customVocabularySubmission.setCustomVocabularies(Arrays.asList(customVocabulary));
26-
customVocabularySubmission.setCallbackUrl("https://example.com");
33+
customVocabularySubmission.setNotificationConfig(notificationUrl, notificationAuth);
2734
customVocabularySubmission.setMetadata("My first submission");
2835

2936
CustomVocabularyInformation submittedCustomVocabularyInfo;
3037

3138
try {
32-
submittedCustomVocabularyInfo =
33-
customVocabulariesClient.submitCustomVocabularies(customVocabularySubmission);
39+
submittedCustomVocabularyInfo = customVocabulariesClient.submitCustomVocabularies(customVocabularySubmission);
3440
} catch (IOException e) {
3541
throw new RuntimeException("Failed to submit custom vocabulary " + e.getMessage());
3642
}
@@ -48,11 +54,9 @@ public static void main(String[] args) {
4854
retrievedVocabularyInfo =
4955
customVocabulariesClient.getCustomVocabularyInformation(customVocabularyId);
5056
} catch (IOException e) {
51-
throw new RuntimeException(
52-
"Failed to retrieve custom vocabulary info ["
53-
+ customVocabularyId
54-
+ "] "
55-
+ e.getMessage());
57+
String message = String.format("Failed to retrieve custom vocabulary info [{0}] {1}", customVocabularyId,
58+
e.getMessage());
59+
throw new RuntimeException(message);
5660
}
5761

5862
CustomVocabularyStatus retrievedVocabularyInfoStatus = retrievedVocabularyInfo.getStatus();

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>ai.rev</groupId>
66
<artifactId>revai-java-sdk</artifactId>
7-
<version>2.0.0</version>
7+
<version>2.1.0</version>
88
<name>Rev AI SDK for Java</name>
99
<description>Java SDK for Rev AI API</description>
1010
<url>https://docs.rev.ai/</url>

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ public String getTranscriptText(String id) throws IOException {
182182
}
183183

184184
/**
185-
* The method sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe
185+
* Sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe
186186
* the media file located at the url provided and returns a {@link RevAiJob} object.
187187
*
188+
* @deprecated Use submitJobUrl with the sourceConfig job option rather than a separate mediaUrl argument
188189
* @param mediaUrl A direct download link to the media.
189190
* @param options The transcription options associated with this job.
190191
* @return RevAiJob A representation of the transcription job.
@@ -194,6 +195,7 @@ public String getTranscriptText(String id) throws IOException {
194195
* @see <a
195196
* href="https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob">https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob</a>
196197
*/
198+
@Deprecated
197199
public RevAiJob submitJobUrl(String mediaUrl, RevAiJobOptions options) throws IOException {
198200
if (mediaUrl == null) {
199201
throw new IllegalArgumentException("Media url must be provided");
@@ -216,7 +218,24 @@ public RevAiJob submitJobUrl(String mediaUrl, RevAiJobOptions options) throws IO
216218
* @see ApiClient#submitJobUrl(String, RevAiJobOptions)
217219
*/
218220
public RevAiJob submitJobUrl(String mediaUrl) throws IOException {
219-
return submitJobUrl(mediaUrl, null);
221+
RevAiJobOptions options = new RevAiJobOptions();
222+
options.setSourceConfig(mediaUrl);
223+
return submitJobUrl(options);
224+
}
225+
226+
/**
227+
* Sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe
228+
* the media file located at the url provided, and returns a {@link RevAiJob} object.
229+
*
230+
* @param options The transcription options associated with this job.
231+
* @return RevAiJob A representation of the transcription job.
232+
* @throws IOException If the response has a status code > 399.
233+
* @see RevAiJob
234+
* @see <a
235+
* href="https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob">https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob</a>
236+
*/
237+
public RevAiJob submitJobUrl(RevAiJobOptions options) throws IOException {
238+
return apiInterface.submitJobUrl(options).execute().body();
220239
}
221240

222241
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public CustomVocabulariesClient(String accessToken) {
4141
* CustomVocabularyInformation} object that provides details about the custom vocabulary
4242
* submission and its progress.
4343
*
44-
* @param submission An object that contains the custom vocabularies as well as optional metadata
45-
* and callback url
44+
* @param submission An object that contains the custom vocabularies and optional parameters
4645
* @return A {@link CustomVocabularyInformation} object.
4746
* @throws IOException If the response has a status code > 399.
4847
* @throws IllegalArgumentException If the list of custom vocabularies is null or empty.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package ai.rev.speechtotext.models;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
import java.util.Map;
6+
7+
public class CustomerUrlData {
8+
/**
9+
* Customer provided url
10+
*/
11+
@SerializedName("url")
12+
private String url;
13+
14+
/**
15+
* Authentication headers to access the url
16+
* Only authorization is currently supported
17+
* Example:
18+
* Map<String, String> authHeaders = new HashMap<>();
19+
* authHeaders.put("Authorization", "Bearer <token>");
20+
* "
21+
*/
22+
@SerializedName("auth_headers")
23+
private Map<String, String> authHeaders;
24+
25+
public CustomerUrlData(String url, Map<String, String> authHeaders) {
26+
this.url = url;
27+
this.authHeaders = authHeaders;
28+
}
29+
30+
public void setUrl(String url) {
31+
this.url = url;
32+
}
33+
34+
public void setAuthHeaders(Map<String, String> authHeaders) {
35+
this.authHeaders = authHeaders;
36+
}
37+
38+
public String getUrl() {
39+
return url;
40+
}
41+
42+
public Map<String, String> getAuthHeaders() {
43+
return authHeaders;
44+
}
45+
}

0 commit comments

Comments
 (0)