- Notifications
You must be signed in to change notification settings - Fork0
revdotcom/revai-java-sdk
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
See theAPI docs for more information about the API.
The recommended way to use the Rev AI Java SDK is to import it into the project using Maven.
<dependency> <groupId>ai.rev</groupId> <artifactId>revai-java-sdk</artifactId> <version>2.2.0</version> </dependency>Once you've cloned the repo you can use Maven to build it locally and install it in your local Maven .m2 repository.
mvn install -DskipTests=trueWe support Java 8 and 11.
All you need to get started is your Access Token, which can be generated onyourSettings Page. Create a client with thegiven Access Token:
// Initialize your client with your Rev AI access tokenString accessToken = "Your Access Token";// Optionally set the Rev AI deployment base url to useString baseUrl = RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl();ApiClient apiClient = new ApiClient(accessToken, baseUrl);RevAiAccount revAiAccount = apiClient.getAccount();You can submit a local file
String localPathToFile = "./path/to/file.mp3";RevAiJob revAiJob = apiClient.submitJobLocalFile(localPathToFile);or submit via a public direct download url
String urlLinkToFile = "https://www.rev.ai/FTC_Sample_1.mp3";RevAiJob revAiJob = apiClient.submitJobUrl(urlLinkToFile);or from FileInputStream, the filename is optional.
File file = new File("./path/to/file.mp3");FileInputStream fileInputStream;try { fileInputStream = new FileInputStream(file);} catch (FileNotFoundException e) { throw new RuntimeException("Could not find file [" + file.getName() + "]");}RevAiJob revAiJob = apiClient.submitJobLocalFile(fileInputStream, String fileName, RevAiJobOptions options);You can request transcript summary.
String urlLinkToFile = "https://www.rev.ai/FTC_Sample_1.mp3";RevAiJobOptions revAiJobOptions = new RevAiJobOptions();revAiJobOptions.setSourceConfig(urlLinkToFile, null);revAiJobOptions.setLanguage("en");revAiJobOptions.setSummarizationOptions(new SummarizationOptions().setModel(NlpModel.STANDARD));You can request transcript translation into up to five languages.
String urlLinkToFile = "https://www.rev.ai/FTC_Sample_1.mp3";RevAiJobOptions revAiJobOptions = new RevAiJobOptions();revAiJobOptions.setSourceConfig(urlLinkToFile, null);revAiJobOptions.setLanguage("en");revAiJobOptions.setTranslationOptions(new TranslationOptions(Arrays.asList( new TranslationLanguageOptions("es") .setModel(NlpModel.PREMIUM), new TranslationLanguageOptions("de")) ));You can also submit a job to be handled by a human transcriber using ourHuman Transcription option.
String urlLinkToFile = "https://www.rev.ai/FTC_Sample_1.mp3";RevAiJobOptions options = new RevAiJobOptions();// set to perform human transcriptionoptions.setTranscriber("human");// optional job optionsoptions.setVerbatim(true);options.setRush(false);options.setTestMode(true);// optional segments to transcribeSegmentToTranscribe segment = new SegmentToTranscribe();segment.setStartTimestamp(2.0);segment.setEndTimestamp(100.5);options.setSegmentsToTranscribe(List.of(segment));// optional speaker names SpeakerName speaker = new SpeakerName();speaker.setDisplayName('Alan Mathison Turing');options.setSpeakerNames(List.of(speaker));RevAiJob revAiJob = apiClient.submitJobUrl(urlLinkToFile, options);RevAiJob objects contain job information as defined by thedocumentation.
If you want to get fancy, all submit job methods have overrides that allow specifyingRevAiJobOptions to configure job specific settings.In RevAiJobOptions, you could includemetadata,notification_config,skip_diarization,skip_punctuation,speaker_channels_count,custom_vocabularies,filter_profanity,remove_disfluencies,delete_after_seconds, andlanguage as optional parameters.
The url submission option also supports authentication headers by using thesource_config option.
All options are described in the request body of theSubmit Job endpoint.
You can check the status of your transcription job using itsid
RevAiJob newlyRefreshedRevAiJob = apiClient.getJobDetails(revAiJob.getJobId());RevAiJob objects contain job information as defined by thedocumentation.
You can retrieve a list of transcription jobs with optional parameters
List<RevAiJob> jobs = apiClient.getListOfJobs();// limit amount of retrieved jobsint numberOfJobsToReturn = 3;List<RevAiJob> jobs = apiClient.getListOfJobs(numberOfJobsToReturn);// get jobs starting after a certain job IDString jobId = "Umx5c6F7pH7r";List<RevAiJob> jobs = apiClient.getListOfJobs(jobId);jobs will contain a list of RevAiJob objects, having all information normally found in a successful responsefrom ourGet List of Jobs endpoint
You can delete a transcription job using itsid
apiClient.deleteJob(revAiJob.getJobId());All data related to the job, such as input media and transcript, will be permanently deleted.A job can only by deleted once it's completed (either with success or failure).
Once your file is transcribed, you can get your transcript in a few different forms:
// as plain textString transcriptText = apiClient.getTranscriptText(revAiJob.getJobId());// or as an objectRevAiTranscript revAiTranscript = apiClient.getTranscriptObject(revAiJob.getJobId());// or if you requested transcript translation(s)RevAiTranscript revAiTranscript = apiClient.getTranslatedTranscriptObject(revAiJob.getJobId(), "es");The text output is a string containing just the text of your transcript. The object form ofthe transcript contains all the information outlined in the response of theGet Transcript endpoint when usingthe json response schema.
Another way to retrieve your file is captions output. We support both .srt and .vtt outputs.See below for an example showing how you can get captions as a readable stream. If your jobwas submitted with multiple speaker channels you are required to provide the id of the channelyou would like captioned.
InputStream inputStream = apiClient.getCaptions(revAiJob.getJobId(), RevAiCaptionType.SRT);// with speaker channelsint channelId = 1;InputStream inputStream = apiClient.getCaptions(revAiJob.getJobId(), RevAiCaptionType.VTT, channelId);// or if you requested transcript translation(s)InputStream inputStream = apiClient.getTranslatedCaptions(revAiJob.getJobId(), "es", RevAiCaptionType.VTT);If you requested transcript summary, you can retrieve it as plain text or structured object:
// as textapiClient.getTranscriptSummaryText(job.id);// as objectapiClient.getTranscriptSummaryObject(job.id);In order to stream audio, you will need to setup a streaming client and the content typefor the audio you will be sending.
StreamContentType streamContentType = new StreamContentType(); streamContentType.setContentType("audio/x-raw"); streamContentType.setLayout("interleaved"); streamContentType.setFormat("S16LE"); streamContentType.setRate(16000); streamContentType.setChannels(1);StreamingClient streamingClient = new StreamingClient("Your Access Token");You will need to create Listener that implements the RevAiWebSocketListener in orderto handle WebSocket events.
publicclassListenerimplementsRevAiWebSocketListener {@OverridepublicvoidonConnected(ConnectedMessagemessage) {System.out.println("On Connected: " +message); }@OverridepublicvoidonHypothesis(Hypothesishypothesis) {System.out.println("On Hypothesis: " +hypothesis); }@OverridepublicvoidonError(Throwablet,Responseresponse) {System.out.println("On Error: " +response.toString()); }@OverridepublicvoidonClose(intcode,Stringreason) {System.out.println("On Close: [" +code +"] " +reason); }@OverridepublicvoidonOpen(Responseresponse) {System.out.println("On Open: " +response.toString()); }}
Now you will be able to connect and start the streaming session by calling thestreamingClient.connect() method and passing in the Listener! You can supply an optionalSessionConfig object, containingmetadata,filter_profanity,remove_disfluencies, anddelete_after_seconds as optional parameters, to the function in order to provide additional information for that session.
Listener listener = new Listener();SessionConfig sessionConfig = new SessionConfig();sessionConfig.setMetaData("My first job");sessionConfig.setFilterProfanity(true);streamingClient.connect(clientListener, streamContentType, sessionConfig);You can stream data over the WebSocket in the form of aByteString using thestreamingClient.sendAudioData() method.
streamingClient.sendAudioData(ByteString);The streaming connection will close when you call the methodstreamingClient.close() or if you go 15 seconds without sending any audio data.
You can submit any custom vocabularies independently through the CustomVocabulariesClient. Once the custom vocabulary has been submitted and processed, it is ready to be used in any async or streaming job.
Below you can see an example of how to create, submit, delete, check on the status and view the other associated information of your custom vocabulary.
// Initialize your client with your Rev AI access tokenString accessToken = "Your Access Token";CustomVocabulariesClient customVocabulariesClient = new CustomVocabulariesClient(accessToken);// Construct a CustomVocabulary object using your desired phrasesList<String> phrases = Arrays.asList("Patrick Henry Winston", "Robert C Berwick", "Noam Chomsky");CustomVocabulary customVocabulary = new CustomVocabulary(phrases);// Submit the CustomVocabularyCustomVocabularyInformation submittedVocabularyInformation = customVocabularyClient.submitCustomVocabularies(Collections.singletonList(customVocabulary));// View the custom vocabulary informationCustomVocabularyInformation retrievedVocabularyInformation = customVocabularyClient.getCustomVocabularyInformation(submittedVocabulary.getId());// View list of custom vocabularies informationList<CustomVocabularyInformation> customVocabulariesInformation = customVocabularyClient.getListOfCustomVocabularyInformation();// Delete a custom vocabulary by idcustomVocabularyClient.deleteCustomVocabulary(retrievedVocabularyInformation.getId());Before contributing to the project please install the following
Before opening a pull-request
- go to
Settings > Pluginsand install google-java-format. - then
Settings > google-java-format Settingsand click enable option. - please run the
Code > Reformat Codeoption in any classes that were touched to ensure the code is formatted correctly.You can also right click onsrcfolder and runReformat Code.
Runmvn package to build the code, run the unit tests and create the SDK jar.
Runmvn verify to also run integration tests. They require theREVAI_ACCESS_TOKEN environment variable to be set to a valid Rev AI access token.
To save theREVAI_ACCESS_TOKEN to be available for Integration tests
- go to
Run > Edit Configurationsand add a new JUnit configuration if none exists yet. - for the new JUnit configuration, go to
Environmental Variablesand click on the browse option. - click
+and addTOKENunder name andREVAI_ACCESS_TOKENunder value.
- Create Github tag
- Creat Github release
- The Github action to publish should kick off
- Remember to update SDK changelog documentation
About
Rev.ai Java SDK
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.