-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLanguageIdLocalMediaFile.java
More file actions
87 lines (73 loc) · 3.17 KB
/
Copy pathLanguageIdLocalMediaFile.java
File metadata and controls
87 lines (73 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package ai.rev;
import ai.rev.languageid.LanguageIdClient;
import ai.rev.languageid.models.LanguageIdJob;
import ai.rev.languageid.models.LanguageIdJobOptions;
import ai.rev.languageid.models.LanguageIdJobStatus;
import ai.rev.languageid.models.LanguageIdResult;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class LanguageIdLocalMediaFile {
public static void main(String[] args) {
// Assign your access token to a String
String accessToken = "<YOUR_ACCESS_TOKEN>";
// Initialize the LanguageIdClient with your access token
LanguageIdClient languageIdClient = new LanguageIdClient(accessToken);
// Initialize the LanguageIdJobOptions object and assign
LanguageIdJobOptions languageIdJobOptions = new LanguageIdJobOptions();
languageIdJobOptions.setMetadata("My first submission");
languageIdJobOptions.setNotificationConfig("https://example.com");
languageIdJobOptions.setDeleteAfterSeconds(2592000); // 30 days in seconds
LanguageIdJob submittedJob;
String localFile = "path/to/file";
try {
// Submit the local file and language id options
submittedJob = languageIdClient.submitJobLocalFile(localFile, languageIdJobOptions);
} catch (IOException e) {
throw new RuntimeException("Failed to submit file [" + localFile + "] " + e.getMessage());
}
String jobId = submittedJob.getJobId();
System.out.println("Job Id: " + jobId);
System.out.println("Job Status: " + submittedJob.getJobStatus());
System.out.println("Created On: " + submittedJob.getCreatedOn());
// Waits 5 seconds between each status check to see if job is complete
boolean isJobComplete = false;
while (!isJobComplete) {
LanguageIdJob retrievedJob;
try {
retrievedJob = languageIdClient.getJobDetails(jobId);
} catch (IOException e) {
throw new RuntimeException("Failed to retrieve job [" + jobId + "] " + e.getMessage());
}
LanguageIdJobStatus retrievedJobStatus = retrievedJob.getJobStatus();
if (retrievedJobStatus == LanguageIdJobStatus.COMPLETED
|| retrievedJobStatus == LanguageIdJobStatus.FAILED) {
isJobComplete = true;
} else {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// Get the language id result
LanguageIdResult languageIdResult;
try {
languageIdResult = languageIdClient.getResultObject(jobId);
System.out.printf("Top Language: %s\n", languageIdResult.getTopLanguage());
for (LanguageConfidence languageConfidence : languageIdResult.getLanguageConfidences()) {
System.out.printf("Language: %s Confidence: %f\n", languageConfidence.getLanguage(), languageConfidence.getConfidence());
}
} catch (IOException e) {
e.printStackTrace();
}
/*
* The job can now be deleted. Deleting the job will remove ALL information
* about the job from the Rev AI servers. Subsequent requests to Rev AI that
* use the deleted jobs Id will return 404's.
*/
// languageIdClient.deleteJob(jobId);
// System.out.printf("Deleted language id job %s", jobId);
}
}