Package ai.rev.speechtotext
Class ApiClient
- java.lang.Object
-
- ai.rev.speechtotext.ApiClient
-
public class ApiClient extends Object
The ApiClient object provides methods to send and retrieve information from all the Rev AI API endpoints using the Retrofit HTTP client.
-
-
Field Summary
Fields Modifier and Type Field Description ApiInterfaceapiInterfaceInterface that ApiClient methods use to make requests
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcloseConnection()Manually closes the connection when the code is running in a JVMvoiddeleteJob(String id)This method sends a DELETE request to the /jobs/{id} endpoint.RevAiAccountgetAccount()This method sends a GET request to the /account endpoint and returns anRevAiAccountobject.InputStreamgetCaptions(String id)An overload ofgetCaptions(String, RevAiCaptionType, Integer)without the optional caption type and channel ID.InputStreamgetCaptions(String id, RevAiCaptionType captionType)An overload ofgetCaptions(String, RevAiCaptionType, Integer)without the optional channel ID.InputStreamgetCaptions(String id, RevAiCaptionType captionType, Integer channelId)The method sends a GET request to the /jobs/{id}/captions endpoint and returns captions for the provided job ID in the form of anInputStream.InputStreamgetCaptions(String id, Integer channelId)An overload ofgetCaptions(String, RevAiCaptionType, Integer)without the optional caption type.RevAiJobgetJobDetails(String id)This method sends a GET request to the /jobs/{id} endpoint and returns aRevAiJobobject.List<RevAiJob>getListOfJobs()Overload ofgetListOfJobs(Integer, String)without the optional limit and startingAfter parameter.List<RevAiJob>getListOfJobs(Integer limit)Overload ofgetListOfJobs(Integer, String)without the optional startingAfter parameter.List<RevAiJob>getListOfJobs(Integer limit, String startingAfter)This method sends a GET request to the /jobs endpoint and returns a list ofRevAiJobobjects.List<RevAiJob>getListOfJobs(String startingAfter)Overload ofgetListOfJobs(Integer, String)without the optional limit parameter.RevAiTranscriptgetTranscriptObject(String id)The method sends a GET request to the /jobs/{id}/transcript endpoint and returns aRevAiTranscriptobject.SummarygetTranscriptSummaryObject(String id)The method sends a GET request to the /jobs/{id}/transcript/summary endpoint and returns the transcript summary as aSummaryobject.StringgetTranscriptSummaryText(String id)The method sends a GET request to the /jobs/{id}/transcript/summary endpoint and returns the transcript summary as a String.StringgetTranscriptText(String id)The method sends a GET request to the /jobs/{id}/transcript endpoint and returns the transcript as a String.InputStreamgetTranslatedCaptions(String id, String language, RevAiCaptionType captionType)The method sends a GET request to the /jobs/{id}/captions/translation/{language} endpoint and returns translated captions for the provided job ID in the form of anInputStream.RevAiTranscriptgetTranslatedTranscriptObject(String id, String language)The method sends a GET request to the /jobs/{id}/transcript/translation/{language} endpoint and returns aRevAiTranscriptobject containing translated transcript.StringgetTranslatedTranscriptText(String id, String language)The method sends a GET request to the /jobs/{id}/transcript/translation/{language} endpoint and returns translated transcript as a String.RevAiJobsubmitJobLocalFile(InputStream inputStream)An overload ofsubmitJobLocalFile(InputStream, String, RevAiJobOptions)without the optional filename and transcription options.RevAiJobsubmitJobLocalFile(InputStream inputStream, RevAiJobOptions options)An overload ofsubmitJobLocalFile(InputStream, String, RevAiJobOptions)without the optional filename.RevAiJobsubmitJobLocalFile(InputStream inputStream, String fileName)An overload ofsubmitJobLocalFile(InputStream, String, RevAiJobOptions)without the additional transcription options.RevAiJobsubmitJobLocalFile(InputStream inputStream, String fileName, RevAiJobOptions options)The method sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe the media file provided by InputStream and returns aRevAiJobobject.RevAiJobsubmitJobLocalFile(String filePath)An overload ofsubmitJobLocalFile(String, RevAiJobOptions)without the additional transcription options.RevAiJobsubmitJobLocalFile(String filePath, RevAiJobOptions options)The method sends multipart/form request to the /jobs endpoint, starts an asynchronous job to transcribe the local media file provided and returns aRevAiJobobject.RevAiJobsubmitJobUrl(RevAiJobOptions options)Sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe the media file located at the url provided, and returns aRevAiJobobject.RevAiJobsubmitJobUrl(String mediaUrl)An overload ofsubmitJobUrl(String, RevAiJobOptions)without the additional transcription options.RevAiJobsubmitJobUrl(String mediaUrl, RevAiJobOptions options)Deprecated.Use submitJobUrl with the sourceConfig job option rather than a separate mediaUrl argument
-
-
-
Field Detail
-
apiInterface
public ApiInterface apiInterface
Interface that ApiClient methods use to make requests
-
-
Constructor Detail
-
ApiClient
public ApiClient(String accessToken, String baseUrl)
Constructs the API client used to send HTTP requests to Rev AI. The user access token can be generated on the website at https://www.rev.ai/access_token.- Parameters:
accessToken- Rev AI authorization token associate with the account.baseUrl- Optional url of the Rev AI API deployment to use, defaults to the US deployement, i.e. 'https://api.rev.ai', which can be referenced as RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl().- Throws:
IllegalArgumentException- If the access token is null or empty.
-
ApiClient
public ApiClient(String accessToken)
Constructs the API client used to send HTTP requests to Rev AI. The user access token can be generated on the website at https://www.rev.ai/access_token.- Parameters:
accessToken- Rev AI authorization token associate with the account.baseUrl- Optional url of the Rev AI API deployment to use, defaults to the US deployement, i.e. 'https://api.rev.ai', which can be referenced as RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl().- Throws:
IllegalArgumentException- If the access token is null or empty.
-
-
Method Detail
-
closeConnection
public void closeConnection()
Manually closes the connection when the code is running in a JVM
-
getAccount
public RevAiAccount getAccount() throws IOException
This method sends a GET request to the /account endpoint and returns anRevAiAccountobject.- Returns:
- RevAiAccount The object containing basic Rev AI account information
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiAccount
-
getListOfJobs
public List<RevAiJob> getListOfJobs(Integer limit, String startingAfter) throws IOException
This method sends a GET request to the /jobs endpoint and returns a list ofRevAiJobobjects.- Parameters:
limit- The maximum number of jobs to return. The default is 100, max is 1000.startingAfter- The job ID at which the list begins.- Returns:
- A list of
RevAiJobobjects. - Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/GetListOfJobs
-
getListOfJobs
public List<RevAiJob> getListOfJobs(Integer limit) throws IOException
Overload ofgetListOfJobs(Integer, String)without the optional startingAfter parameter.- Parameters:
limit- The maximum number of jobs to return. The default is 100, max is 1000.- Returns:
- A list of
RevAiJobobjects. - Throws:
IOException- If the response has a status code > 399.
-
getListOfJobs
public List<RevAiJob> getListOfJobs(String startingAfter) throws IOException
Overload ofgetListOfJobs(Integer, String)without the optional limit parameter.- Parameters:
startingAfter- The job ID at which the list begins.- Returns:
- A list of
RevAiJobobjects. - Throws:
IOException- If the response has a status code > 399.
-
getListOfJobs
public List<RevAiJob> getListOfJobs() throws IOException
Overload ofgetListOfJobs(Integer, String)without the optional limit and startingAfter parameter.- Returns:
- A list of
RevAiJobobjects. - Throws:
IOException- If the response has a status code > 399.
-
getJobDetails
public RevAiJob getJobDetails(String id) throws IOException
This method sends a GET request to the /jobs/{id} endpoint and returns aRevAiJobobject.- Parameters:
id- The ID of the job to return an object for.- Returns:
- A
RevAiJobobject. - Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the job ID is null.
-
deleteJob
public void deleteJob(String id) throws IOException
This method sends a DELETE request to the /jobs/{id} endpoint.- Parameters:
id- The Id of the job to be deleted.- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the job ID is null.- See Also:
- https://docs.rev.ai/api/asynchronous/reference/#operation/DeleteJobById
-
getTranscriptObject
public RevAiTranscript getTranscriptObject(String id) throws IOException
The method sends a GET request to the /jobs/{id}/transcript endpoint and returns aRevAiTranscriptobject.- Parameters:
id- The ID of the job to return a transcript for.- Returns:
- RevAiTranscript The transcript object.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiTranscript
-
getTranslatedTranscriptText
public String getTranslatedTranscriptText(String id, String language) throws IOException
The method sends a GET request to the /jobs/{id}/transcript/translation/{language} endpoint and returns translated transcript as a String.- Parameters:
id- The ID of the job to return a transcript for.language- requested transcript language.- Returns:
- The transcript as a String in text format.
- Throws:
IOException- If the response has a status code > 399.
-
getTranslatedTranscriptObject
public RevAiTranscript getTranslatedTranscriptObject(String id, String language) throws IOException
The method sends a GET request to the /jobs/{id}/transcript/translation/{language} endpoint and returns aRevAiTranscriptobject containing translated transcript.- Parameters:
id- The ID of the job to return a transcript for.language- requested transcript language.- Returns:
- RevAiTranscript The transcript object.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiTranscript
-
getTranscriptText
public String getTranscriptText(String id) throws IOException
The method sends a GET request to the /jobs/{id}/transcript endpoint and returns the transcript as a String.- Parameters:
id- The ID of the job to return a transcript for.- Returns:
- The transcript as a String in text format.
- Throws:
IOException- If the response has a status code > 399.
-
getTranscriptSummaryText
public String getTranscriptSummaryText(String id) throws IOException
The method sends a GET request to the /jobs/{id}/transcript/summary endpoint and returns the transcript summary as a String.- Parameters:
id- The ID of the job to return a transcript summary for.- Returns:
- The transcript summary as a String in text format.
- Throws:
IOException- If the response has a status code > 399.
-
getTranscriptSummaryObject
public Summary getTranscriptSummaryObject(String id) throws IOException
The method sends a GET request to the /jobs/{id}/transcript/summary endpoint and returns the transcript summary as aSummaryobject.- Parameters:
id- The ID of the job to return a transcript summary for.- Returns:
- The transcript summary as a String in text format.
- Throws:
IOException- If the response has a status code > 399.
-
submitJobUrl
@Deprecated public RevAiJob submitJobUrl(String mediaUrl, RevAiJobOptions options) throws IOException
Deprecated.Use submitJobUrl with the sourceConfig job option rather than a separate mediaUrl argumentSends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe the media file located at the url provided and returns aRevAiJobobject.- Parameters:
mediaUrl- A direct download link to the media.options- The transcription options associated with this job.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- if the media url is null.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
-
submitJobUrl
public RevAiJob submitJobUrl(String mediaUrl) throws IOException
An overload ofsubmitJobUrl(String, RevAiJobOptions)without the additional transcription options.- Parameters:
mediaUrl- A direct download link to the media.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiJob,submitJobUrl(String, RevAiJobOptions)
-
submitJobUrl
public RevAiJob submitJobUrl(RevAiJobOptions options) throws IOException
Sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe the media file located at the url provided, and returns aRevAiJobobject.- Parameters:
options- The transcription options associated with this job.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
-
submitJobLocalFile
public RevAiJob submitJobLocalFile(String filePath, RevAiJobOptions options) throws IOException
The method sends multipart/form request to the /jobs endpoint, starts an asynchronous job to transcribe the local media file provided and returns aRevAiJobobject.- Parameters:
filePath- A local path to the file on the computer.options- The transcription options associated with this job.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the file path is null.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
-
submitJobLocalFile
public RevAiJob submitJobLocalFile(String filePath) throws IOException
An overload ofsubmitJobLocalFile(String, RevAiJobOptions)without the additional transcription options.- Parameters:
filePath- A local path to the file on the computer.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiJob,submitJobLocalFile(String, RevAiJobOptions)
-
submitJobLocalFile
public RevAiJob submitJobLocalFile(InputStream inputStream, String fileName, RevAiJobOptions options) throws IOException
The method sends a POST request to the /jobs endpoint, starts an asynchronous job to transcribe the media file provided by InputStream and returns aRevAiJobobject.- Parameters:
inputStream- An InputStream of the media file.fileName- The name of the file being streamed.options- The transcription options associated with this job.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the InputStream provided is null.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
-
submitJobLocalFile
public RevAiJob submitJobLocalFile(InputStream inputStream) throws IOException
An overload ofsubmitJobLocalFile(InputStream, String, RevAiJobOptions)without the optional filename and transcription options.- Parameters:
inputStream- An InputStream of the media file.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
-
submitJobLocalFile
public RevAiJob submitJobLocalFile(InputStream inputStream, String fileName) throws IOException
An overload ofsubmitJobLocalFile(InputStream, String, RevAiJobOptions)without the additional transcription options.- Parameters:
inputStream- An InputStream of the media file.fileName- The name of the file being streamed.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
-
submitJobLocalFile
public RevAiJob submitJobLocalFile(InputStream inputStream, RevAiJobOptions options) throws IOException
An overload ofsubmitJobLocalFile(InputStream, String, RevAiJobOptions)without the optional filename.- Parameters:
inputStream- An InputStream of the media file.options- The transcription options associated with this job.- Returns:
- RevAiJob A representation of the transcription job.
- Throws:
IOException- If the response has a status code > 399.- See Also:
RevAiJob, https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
-
getCaptions
public InputStream getCaptions(String id, RevAiCaptionType captionType, Integer channelId) throws IOException
The method sends a GET request to the /jobs/{id}/captions endpoint and returns captions for the provided job ID in the form of anInputStream.- Parameters:
id- The ID of the job to return captions for.captionType- An enumeration of the desired caption type. Default is SRT.channelId- Identifies the audio channel of the file to output captions for. Default is null.- Returns:
- InputStream A stream of bytes that represents the caption output.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the job ID provided is null.- See Also:
- https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions
-
getTranslatedCaptions
public InputStream getTranslatedCaptions(String id, String language, RevAiCaptionType captionType) throws IOException
The method sends a GET request to the /jobs/{id}/captions/translation/{language} endpoint and returns translated captions for the provided job ID in the form of anInputStream.- Parameters:
id- The ID of the job to return captions for.language- requested translation language.captionType- An enumeration of the desired caption type. Default is SRT.- Returns:
- InputStream A stream of bytes that represents the caption output.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the job ID provided is null.- See Also:
- https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions
-
getCaptions
public InputStream getCaptions(String id, RevAiCaptionType captionType) throws IOException
An overload ofgetCaptions(String, RevAiCaptionType, Integer)without the optional channel ID.- Parameters:
id- The ID of the job to return captions for.captionType- An enumeration of the desired caption type. Default is SRT- Returns:
- InputStream A stream of bytes that represents the caption output.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the job ID provided is null.- See Also:
- https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions
-
getCaptions
public InputStream getCaptions(String id, Integer channelId) throws IOException
An overload ofgetCaptions(String, RevAiCaptionType, Integer)without the optional caption type.- Parameters:
id- The ID of the job to return captions for.channelId- Identifies the audio channel of the file to output captions for.- Returns:
- InputStream A stream of bytes that represents the caption output.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the job ID provided is null.- See Also:
- https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions
-
getCaptions
public InputStream getCaptions(String id) throws IOException
An overload ofgetCaptions(String, RevAiCaptionType, Integer)without the optional caption type and channel ID.- Parameters:
id- The ID of the job to return captions for.- Returns:
- InputStream A stream of bytes that represents the caption output.
- Throws:
IOException- If the response has a status code > 399.IllegalArgumentException- If the job ID provided is null.- See Also:
- https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions
-
-