Skip to content

Commit

Permalink
Merge pull request #119 from AssemblyAI/niels/add-file-path-overloads
Browse files Browse the repository at this point in the history
Add overload to files and transcript client
  • Loading branch information
Swimburger authored Aug 22, 2024
2 parents d1c5a72 + 40c257b commit 155c778
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 8 deletions.
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/assemblyai/api/AssemblyAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +15,7 @@
public class AssemblyAI {
protected final ClientOptions clientOptions;

protected final Supplier<FilesClient> filesClient;
protected final Supplier<ExtendedFilesClient> filesClient;

protected final Supplier<PollingTranscriptsClient> transcriptClient;

Expand All @@ -24,21 +25,21 @@ 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));
}

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();
}

Expand Down
85 changes: 83 additions & 2 deletions src/main/java/com/assemblyai/api/PollingTranscriptsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/assemblyai/api/core/Constants.java
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 155c778

Please sign in to comment.