diff --git a/.fernignore b/.fernignore index 68a71a86..83245797 100644 --- a/.fernignore +++ b/.fernignore @@ -1,6 +1,7 @@ # Specify files that shouldn't be modified by Fern src/main/java/com/assemblyai/api/AssemblyAI.java src/main/java/com/assemblyai/api/PollingTranscriptsClient.java +src/main/java/com/assemblyai/api/resources/files/ExtendedFilesClient.java src/main/java/com/assemblyai/api/Transcriber.java src/main/java/com/assemblyai/api/RealtimeTranscriber.java src/main/java/com/assemblyai/api/core/Constants.java diff --git a/build.gradle b/build.gradle index 87da592d..609558fc 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ publishing { maven(MavenPublication) { groupId = 'com.assemblyai' artifactId = 'assemblyai-java' - version = '2.1.4' + version = '2.2.0' from components.java pom { scm { diff --git a/src/main/java/com/assemblyai/api/AssemblyAI.java b/src/main/java/com/assemblyai/api/AssemblyAI.java index abda3a75..8f87f27b 100644 --- a/src/main/java/com/assemblyai/api/AssemblyAI.java +++ b/src/main/java/com/assemblyai/api/AssemblyAI.java @@ -5,6 +5,7 @@ import com.assemblyai.api.core.ClientOptions; import com.assemblyai.api.core.Suppliers; +import com.assemblyai.api.resources.files.ExtendedFilesClient; import com.assemblyai.api.resources.files.FilesClient; import com.assemblyai.api.resources.lemur.LemurClient; import com.assemblyai.api.resources.realtime.RealtimeClient; @@ -14,7 +15,7 @@ public class AssemblyAI { protected final ClientOptions clientOptions; - protected final Supplier filesClient; + protected final Supplier filesClient; protected final Supplier transcriptClient; @@ -24,7 +25,7 @@ public class AssemblyAI { public AssemblyAI(ClientOptions clientOptions) { this.clientOptions = clientOptions; - this.filesClient = Suppliers.memoize(() -> new FilesClient(clientOptions)); + this.filesClient = Suppliers.memoize(() -> new ExtendedFilesClient(clientOptions)); this.transcriptClient = Suppliers.memoize(() -> new PollingTranscriptsClient(clientOptions, this)); this.realtimeClient = Suppliers.memoize(() -> new RealtimeClient(clientOptions)); this.lemurClient = Suppliers.memoize(() -> new LemurClient(clientOptions)); @@ -32,13 +33,13 @@ public AssemblyAI(ClientOptions clientOptions) { public AssemblyAI(ClientOptions clientOptions, ClientOptions lemurClientOptions) { this.clientOptions = clientOptions; - this.filesClient = Suppliers.memoize(() -> new FilesClient(clientOptions)); + this.filesClient = Suppliers.memoize(() -> new ExtendedFilesClient(clientOptions)); this.transcriptClient = Suppliers.memoize(() -> new PollingTranscriptsClient(clientOptions, this)); this.realtimeClient = Suppliers.memoize(() -> new RealtimeClient(clientOptions)); this.lemurClient = Suppliers.memoize(() -> new LemurClient(lemurClientOptions)); } - public FilesClient files() { + public ExtendedFilesClient files() { return this.filesClient.get(); } diff --git a/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java b/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java index 8b3696eb..f3a57f7b 100644 --- a/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java +++ b/src/main/java/com/assemblyai/api/PollingTranscriptsClient.java @@ -14,6 +14,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; public class PollingTranscriptsClient extends TranscriptsClient { @@ -35,7 +36,7 @@ public PollingTranscriptsClient(ClientOptions clientOptions, AssemblyAI client) * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript submit(File file) throws IOException { - return submit(file, EMPTY_PARAMS); + return submit(file.toPath(), EMPTY_PARAMS); } /** @@ -46,10 +47,48 @@ public Transcript submit(File file) throws IOException { * @throws IOException The file will be read and an IOException may be thrown. */ public Transcript submit(File file, TranscriptOptionalParams transcriptParams) throws IOException { - UploadedFile uploadedFile = client.files().upload(Files.readAllBytes(file.toPath())); + return submit(file.toPath(), transcriptParams); + } + + /** + * 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); + } + + /** + * 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, TranscriptOptionalParams transcriptParams) throws IOException { + UploadedFile uploadedFile = client.files().upload(filePath); return submit(uploadedFile.getUploadUrl(), transcriptParams); } + /** + * 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); + } + + /** + * 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, TranscriptOptionalParams transcriptParams) { + return submit(file.getUploadUrl(), transcriptParams); + } + /** * 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 @@ -107,6 +146,28 @@ public Transcript submit(String url, TranscriptOptionalParams transcriptParams) return super.submit(createTranscriptParams); } + /** + * 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); + } + + /** + * 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); + } + /** * 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 @@ -129,6 +190,26 @@ public Transcript transcribe(File file, TranscriptOptionalParams transcriptParam return transcribe(uploadedFile.getUploadUrl(), transcriptParams); } + /** + * 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" + * @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); + } + + /** + * 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); + } + /** * 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 diff --git a/src/main/java/com/assemblyai/api/core/Constants.java b/src/main/java/com/assemblyai/api/core/Constants.java index d00eacaf..df2f0ce5 100644 --- a/src/main/java/com/assemblyai/api/core/Constants.java +++ b/src/main/java/com/assemblyai/api/core/Constants.java @@ -1,5 +1,5 @@ package com.assemblyai.api.core; public class Constants { - public static final String SDK_VERSION = "2.1.4"; + public static final String SDK_VERSION = "2.2.0"; } diff --git a/src/main/java/com/assemblyai/api/resources/files/ExtendedFilesClient.java b/src/main/java/com/assemblyai/api/resources/files/ExtendedFilesClient.java new file mode 100644 index 00000000..65f4db27 --- /dev/null +++ b/src/main/java/com/assemblyai/api/resources/files/ExtendedFilesClient.java @@ -0,0 +1,43 @@ +package com.assemblyai.api.resources.files; + +import com.assemblyai.api.core.*; +import com.assemblyai.api.resources.files.types.UploadedFile; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class ExtendedFilesClient extends FilesClient { + public ExtendedFilesClient(ClientOptions clientOptions) { + super(clientOptions); + } + + /** + * Upload a media file to AssemblyAI's servers. + */ + public UploadedFile upload(File file) throws IOException { + return upload(file, null); + } + + /** + * Upload a media file to AssemblyAI's servers. + */ + public UploadedFile upload(File file, RequestOptions requestOptions) throws IOException { + return upload(file.toPath(), requestOptions); + } + + /** + * Upload a media file to AssemblyAI's servers. + */ + public UploadedFile upload(Path filePath) throws IOException { + return upload(filePath, null); + } + + /** + * Upload a media file to AssemblyAI's servers. + */ + public UploadedFile upload(Path filePath, RequestOptions requestOptions) throws IOException { + return upload(Files.readAllBytes(filePath), requestOptions); + } +}