From 91b1053e6a5d9877be2942d757af1348c6383ace Mon Sep 17 00:00:00 2001 From: Niels Swimberghe <3382717+Swimburger@users.noreply.github.com> Date: Tue, 10 Sep 2024 11:42:50 -0400 Subject: [PATCH] Add RequestOptions to PollingTranscriptsClient methods --- .../api/PollingTranscriptsClient.java | 324 ++++++++++++++++-- 1 file changed, 294 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java b/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java index f3a57f7b..13e0209f 100644 --- a/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java +++ b/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java @@ -31,80 +31,208 @@ public PollingTranscriptsClient(ClientOptions clientOptions, AssemblyAI client) /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * * @param file Audio file to transcribe * @return Queued transcript * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript submit(File file) throws IOException { - return submit(file.toPath(), EMPTY_PARAMS); + return submit(file.toPath(), EMPTY_PARAMS, null); } /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". - * @param file Audio file to transcribe + * + * @param file Audio file to transcribe + * @param requestOptions The HTTP request options + * @return Queued transcript + * @throws IOException The file will be read and an IOException may be thrown. + */ + public Transcript submit(File file, RequestOptions requestOptions) throws IOException { + return submit(file.toPath(), EMPTY_PARAMS, requestOptions); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param file Audio file to transcribe * @param transcriptParams The parameters to transcribe an audio file. * @return Queued transcript * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript submit(File file, TranscriptOptionalParams transcriptParams) throws IOException { - return submit(file.toPath(), transcriptParams); + return submit(file.toPath(), transcriptParams, null); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param file Audio file to transcribe + * @param transcriptParams The parameters to transcribe an audio file. + * @param requestOptions The HTTP request options + * @return Queued transcript + * @throws IOException The file will be read and an IOException may be thrown. + */ + public Transcript submit( + File file, + TranscriptOptionalParams transcriptParams, + RequestOptions requestOptions + ) throws IOException { + return submit(file.toPath(), transcriptParams, requestOptions); } /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * * @param filePath Path to audio file to transcribe * @return Queued transcript * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript submit(Path filePath) throws IOException { - return submit(filePath, EMPTY_PARAMS); + return submit(filePath, EMPTY_PARAMS, null); } /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". - * @param filePath Path to audio file to transcribe + * + * @param filePath Path to audio file to transcribe + * @param requestOptions The HTTP request options + * @return Queued transcript + * @throws IOException The file will be read and an IOException may be thrown. + */ + public Transcript submit( + Path filePath, + RequestOptions requestOptions + ) throws IOException { + return submit(filePath, EMPTY_PARAMS, requestOptions); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param filePath Path to audio file to transcribe + * @param transcriptParams The parameters to transcribe an audio file. * @return Queued transcript * @throws IOException The file will be read and an IOException may be thrown. */ - public Transcript submit(Path filePath, TranscriptOptionalParams transcriptParams) throws IOException { + public Transcript submit( + Path filePath, + TranscriptOptionalParams transcriptParams + ) throws IOException { UploadedFile uploadedFile = client.files().upload(filePath); - return submit(uploadedFile.getUploadUrl(), transcriptParams); + return submit(uploadedFile.getUploadUrl(), transcriptParams, null); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param filePath Path to audio file to transcribe + * @param transcriptParams The parameters to transcribe an audio file. + * @param requestOptions The HTTP request options + * @return Queued transcript + * @throws IOException The file will be read and an IOException may be thrown. + */ + public Transcript submit( + Path filePath, + TranscriptOptionalParams transcriptParams, + RequestOptions requestOptions + ) throws IOException { + UploadedFile uploadedFile = client.files().upload(filePath, requestOptions); + return submit(uploadedFile.getUploadUrl(), transcriptParams, requestOptions); } /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * * @param file The file uploaded to AssemblyAI * @return Queued transcript */ public Transcript submit(UploadedFile file) { - return submit(file.getUploadUrl(), EMPTY_PARAMS); + return submit(file.getUploadUrl(), EMPTY_PARAMS, null); } /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". - * @param file The file uploaded to AssemblyAI + * + * @param file The file uploaded to AssemblyAI + * @param requestOptions The HTTP request options + * @return Queued transcript + */ + public Transcript submit( + UploadedFile file, + RequestOptions requestOptions + ) { + return submit(file.getUploadUrl(), EMPTY_PARAMS, requestOptions); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param file The file uploaded to AssemblyAI + * @param transcriptParams The parameters to transcribe an audio file. * @return Queued transcript */ public Transcript submit(UploadedFile file, TranscriptOptionalParams transcriptParams) { - return submit(file.getUploadUrl(), transcriptParams); + return submit(file.getUploadUrl(), transcriptParams, null); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param file The file uploaded to AssemblyAI + * @param transcriptParams The parameters to transcribe an audio file. + * @param requestOptions The HTTP request options + * @return Queued transcript + */ + public Transcript submit( + UploadedFile file, + TranscriptOptionalParams transcriptParams, + RequestOptions requestOptions + ) { + return submit(file.getUploadUrl(), transcriptParams, requestOptions); } /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * * @param url URL to the audio file to transcribe * @return Queued transcript */ public Transcript submit(String url) { - return submit(url, EMPTY_PARAMS); + return submit(url, EMPTY_PARAMS, null); } /** * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". - * @param url URL to the audio file to transcribe + * + * @param url URL to the audio file to transcribe + * @param requestOptions The HTTP request options + * @return Queued transcript + */ + public Transcript submit(String url, RequestOptions requestOptions) { + return submit(url, EMPTY_PARAMS, requestOptions); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param url URL to the audio file to transcribe * @param transcriptParams The parameters to transcribe an audio file. * @return Queued transcript */ public Transcript submit(String url, TranscriptOptionalParams transcriptParams) { + return submit(url, transcriptParams, null); + } + + /** + * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error". + * + * @param url URL to the audio file to transcribe + * @param transcriptParams The parameters to transcribe an audio file. + * @param requestOptions The HTTP request options + * @return Queued transcript + */ + public Transcript submit(String url, TranscriptOptionalParams transcriptParams, RequestOptions requestOptions) { TranscriptParams createTranscriptParams = TranscriptParams.builder() .audioUrl(url) .languageCode(transcriptParams.getLanguageCode()) @@ -143,112 +271,241 @@ public Transcript submit(String url, TranscriptOptionalParams transcriptParams) .customTopics(transcriptParams.getCustomTopics()) .topics(transcriptParams.getTopics()) .build(); - return super.submit(createTranscriptParams); + return super.submit(createTranscriptParams, requestOptions); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * * @param filePath Audio file to transcribe * @return A transcript with status "completed" or "error" * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript transcribe(Path filePath) throws IOException { - return transcribe(filePath, EMPTY_PARAMS); + return transcribe(filePath, EMPTY_PARAMS, null); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". - * @param filePath Audio file to transcribe + * + * @param filePath Audio file to transcribe + * @param requestOptions The HTTP request options + * @return A transcript with status "completed" or "error" + * @throws IOException The file will be read and an IOException may be thrown. + */ + public Transcript transcribe(Path filePath, RequestOptions requestOptions) throws IOException { + return transcribe(filePath, EMPTY_PARAMS, requestOptions); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param filePath Audio file to transcribe * @param transcriptParams The parameters to transcribe an audio file. * @return A transcript with status "completed" or "error" * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript transcribe(Path filePath, TranscriptOptionalParams transcriptParams) throws IOException { UploadedFile uploadedFile = client.files().upload(filePath); - return transcribe(uploadedFile.getUploadUrl(), transcriptParams); + return transcribe(uploadedFile.getUploadUrl(), transcriptParams, null); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param filePath Audio file to transcribe + * @param transcriptParams The parameters to transcribe an audio file. + * @param requestOptions The HTTP request options + * @return A transcript with status "completed" or "error" + * @throws IOException The file will be read and an IOException may be thrown. + */ + public Transcript transcribe(Path filePath, TranscriptOptionalParams transcriptParams, RequestOptions requestOptions) throws IOException { + UploadedFile uploadedFile = client.files().upload(filePath, requestOptions); + return transcribe(uploadedFile.getUploadUrl(), transcriptParams, requestOptions); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * * @param file Audio file to transcribe * @return A transcript with status "completed" or "error" * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript transcribe(File file) throws IOException { - return transcribe(file, EMPTY_PARAMS); + return transcribe(file, EMPTY_PARAMS, null); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". - * @param file Audio file to transcribe + * + * @param file Audio file to transcribe + * @param requestOptions The HTTP request options + * @return A transcript with status "completed" or "error" + * @throws IOException The file will be read and an IOException may be thrown. + */ + public Transcript transcribe(File file, RequestOptions requestOptions) throws IOException { + return transcribe(file, EMPTY_PARAMS, requestOptions); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param file Audio file to transcribe * @param transcriptParams The parameters to transcribe an audio file. * @return A transcript with status "completed" or "error" * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript transcribe(File file, TranscriptOptionalParams transcriptParams) throws IOException { - UploadedFile uploadedFile = client.files().upload(Files.readAllBytes(file.toPath())); - return transcribe(uploadedFile.getUploadUrl(), transcriptParams); + return transcribe(file, transcriptParams, null); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". - * @param file The file uploaded to AssemblyAI + * + * @param file Audio file to transcribe + * @param transcriptParams The parameters to transcribe an audio file. + * @param requestOptions The HTTP request options * @return A transcript with status "completed" or "error" * @throws IOException The file will be read and an IOException may be thrown. */ - public Transcript transcribe(UploadedFile file) throws IOException { - return transcribe(file, EMPTY_PARAMS); + public Transcript transcribe( + File file, + TranscriptOptionalParams transcriptParams, + RequestOptions requestOptions + ) throws IOException { + UploadedFile uploadedFile = client.files().upload(Files.readAllBytes(file.toPath()), requestOptions); + return transcribe(uploadedFile.getUploadUrl(), transcriptParams, requestOptions); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * * @param file The file uploaded to AssemblyAI + * @return A transcript with status "completed" or "error" + */ + public Transcript transcribe(UploadedFile file) { + return transcribe(file, EMPTY_PARAMS, null); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param file The file uploaded to AssemblyAI + * @param requestOptions The HTTP request options + * @return A transcript with status "completed" or "error" + */ + public Transcript transcribe(UploadedFile file, RequestOptions requestOptions) { + return transcribe(file, EMPTY_PARAMS, requestOptions); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param file The file uploaded to AssemblyAI * @param transcriptParams The parameters to transcribe an audio file. * @return A transcript with status "completed" or "error" */ public Transcript transcribe(UploadedFile file, TranscriptOptionalParams transcriptParams) { - return transcribe(file.getUploadUrl(), transcriptParams); + return transcribe(file.getUploadUrl(), transcriptParams, null); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param file The file uploaded to AssemblyAI + * @param transcriptParams The parameters to transcribe an audio file + * @param requestOptions The HTTP request options. + * @return A transcript with status "completed" or "error" + */ + public Transcript transcribe( + UploadedFile file, + TranscriptOptionalParams transcriptParams, + RequestOptions requestOptions + ) { + return transcribe(file.getUploadUrl(), transcriptParams, requestOptions); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * * @param url URL to the audio file to transcribe * @return A transcript with status "completed" or "error" */ public Transcript transcribe(String url) { - return transcribe(url, EMPTY_PARAMS); + return transcribe(url, EMPTY_PARAMS, null); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". - * @param url URL to the audio file to transcribe + * + * @param url URL to the audio file to transcribe + * @param requestOptions The HTTP request options + * @return A transcript with status "completed" or "error" + */ + public Transcript transcribe(String url, RequestOptions requestOptions) { + return transcribe(url, EMPTY_PARAMS, requestOptions); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param url URL to the audio file to transcribe * @param transcriptParams The parameters to transcribe an audio file. * @return A transcript with status "completed" or "error" */ public Transcript transcribe(String url, TranscriptOptionalParams transcriptParams) { - Transcript transcriptResponse = submit(url, transcriptParams); - return waitUntilReady(transcriptResponse.getId()); + return transcribe(url, transcriptParams, null); + } + + /** + * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * + * @param url URL to the audio file to transcribe + * @param transcriptParams The parameters to transcribe an audio file. + * @param requestOptions The HTTP request options + * @return A transcript with status "completed" or "error" + */ + public Transcript transcribe( + String url, + TranscriptOptionalParams transcriptParams, + RequestOptions requestOptions + ) { + Transcript transcriptResponse = submit(url, transcriptParams, requestOptions); + return waitUntilReady(transcriptResponse.getId(), requestOptions); } /** * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error". + * * @param transcriptParams The parameters to transcribe an audio file. * @return A transcript with status "completed" or "error" */ public Transcript transcribe(TranscriptParams transcriptParams) { - Transcript transcriptResponse = submit(transcriptParams); + Transcript transcriptResponse = submit(transcriptParams, null); return waitUntilReady(transcriptResponse.getId()); } /** * Wait until an existing transcript has the status "completed" or "error". + * * @param transcriptId The ID of the transcript * @return The transcript with status "completed" or "error" */ public Transcript waitUntilReady(String transcriptId) { + return waitUntilReady(transcriptId, null); + } + + /** + * Wait until an existing transcript has the status "completed" or "error". + * + * @param transcriptId The ID of the transcript + * @param requestOptions The HTTP request options + * @return The transcript with status "completed" or "error" + */ + public Transcript waitUntilReady(String transcriptId, RequestOptions requestOptions) { try { while (true) { - Transcript transcript = this.client.transcripts().get(transcriptId); + Transcript transcript = this.client.transcripts().get(transcriptId, requestOptions); TranscriptStatus status = transcript.getStatus(); if (status.equals(TranscriptStatus.COMPLETED) || status.equals(TranscriptStatus.ERROR)) { return transcript; @@ -262,6 +519,9 @@ public Transcript waitUntilReady(String transcriptId) { /** * Search through the transcript for a specific set of keywords. You can search for individual words, numbers, or phrases containing up to five words or numbers. + * + * @param transcriptId The ID of the transcript + * @param words Keywords to search for */ public WordSearchResponse wordSearch(String transcriptId, List words) { return wordSearch(transcriptId, words, null); @@ -269,6 +529,10 @@ public WordSearchResponse wordSearch(String transcriptId, List words) { /** * Search through the transcript for a specific set of keywords. You can search for individual words, numbers, or phrases containing up to five words or numbers. + * + * @param transcriptId The ID of the transcript + * @param words Keywords to search for + * @param requestOptions The HTTP request options */ public WordSearchResponse wordSearch(String transcriptId, List words, RequestOptions requestOptions) { return wordSearch(