Skip to content

Commit 155c778

Browse files
authored
Merge pull request #119 from AssemblyAI/niels/add-file-path-overloads
Add overload to files and transcript client
2 parents d1c5a72 + 40c257b commit 155c778

File tree

6 files changed

+134
-8
lines changed

6 files changed

+134
-8
lines changed

.fernignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Specify files that shouldn't be modified by Fern
22
src/main/java/com/assemblyai/api/AssemblyAI.java
33
src/main/java/com/assemblyai/api/PollingTranscriptsClient.java
4+
src/main/java/com/assemblyai/api/resources/files/ExtendedFilesClient.java
45
src/main/java/com/assemblyai/api/Transcriber.java
56
src/main/java/com/assemblyai/api/RealtimeTranscriber.java
67
src/main/java/com/assemblyai/api/core/Constants.java

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ publishing {
4747
maven(MavenPublication) {
4848
groupId = 'com.assemblyai'
4949
artifactId = 'assemblyai-java'
50-
version = '2.1.4'
50+
version = '2.2.0'
5151
from components.java
5252
pom {
5353
scm {

src/main/java/com/assemblyai/api/AssemblyAI.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.assemblyai.api.core.ClientOptions;
77
import com.assemblyai.api.core.Suppliers;
8+
import com.assemblyai.api.resources.files.ExtendedFilesClient;
89
import com.assemblyai.api.resources.files.FilesClient;
910
import com.assemblyai.api.resources.lemur.LemurClient;
1011
import com.assemblyai.api.resources.realtime.RealtimeClient;
@@ -14,7 +15,7 @@
1415
public class AssemblyAI {
1516
protected final ClientOptions clientOptions;
1617

17-
protected final Supplier<FilesClient> filesClient;
18+
protected final Supplier<ExtendedFilesClient> filesClient;
1819

1920
protected final Supplier<PollingTranscriptsClient> transcriptClient;
2021

@@ -24,21 +25,21 @@ public class AssemblyAI {
2425

2526
public AssemblyAI(ClientOptions clientOptions) {
2627
this.clientOptions = clientOptions;
27-
this.filesClient = Suppliers.memoize(() -> new FilesClient(clientOptions));
28+
this.filesClient = Suppliers.memoize(() -> new ExtendedFilesClient(clientOptions));
2829
this.transcriptClient = Suppliers.memoize(() -> new PollingTranscriptsClient(clientOptions, this));
2930
this.realtimeClient = Suppliers.memoize(() -> new RealtimeClient(clientOptions));
3031
this.lemurClient = Suppliers.memoize(() -> new LemurClient(clientOptions));
3132
}
3233

3334
public AssemblyAI(ClientOptions clientOptions, ClientOptions lemurClientOptions) {
3435
this.clientOptions = clientOptions;
35-
this.filesClient = Suppliers.memoize(() -> new FilesClient(clientOptions));
36+
this.filesClient = Suppliers.memoize(() -> new ExtendedFilesClient(clientOptions));
3637
this.transcriptClient = Suppliers.memoize(() -> new PollingTranscriptsClient(clientOptions, this));
3738
this.realtimeClient = Suppliers.memoize(() -> new RealtimeClient(clientOptions));
3839
this.lemurClient = Suppliers.memoize(() -> new LemurClient(lemurClientOptions));
3940
}
4041

41-
public FilesClient files() {
42+
public ExtendedFilesClient files() {
4243
return this.filesClient.get();
4344
}
4445

src/main/java/com/assemblyai/api/PollingTranscriptsClient.java

+83-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.File;
1515
import java.io.IOException;
1616
import java.nio.file.Files;
17+
import java.nio.file.Path;
1718
import java.util.List;
1819

1920
public class PollingTranscriptsClient extends TranscriptsClient {
@@ -35,7 +36,7 @@ public PollingTranscriptsClient(ClientOptions clientOptions, AssemblyAI client)
3536
* @throws IOException The file will be read and an IOException may be thrown.
3637
*/
3738
public Transcript submit(File file) throws IOException {
38-
return submit(file, EMPTY_PARAMS);
39+
return submit(file.toPath(), EMPTY_PARAMS);
3940
}
4041

4142
/**
@@ -46,10 +47,48 @@ public Transcript submit(File file) throws IOException {
4647
* @throws IOException The file will be read and an IOException may be thrown.
4748
*/
4849
public Transcript submit(File file, TranscriptOptionalParams transcriptParams) throws IOException {
49-
UploadedFile uploadedFile = client.files().upload(Files.readAllBytes(file.toPath()));
50+
return submit(file.toPath(), transcriptParams);
51+
}
52+
53+
/**
54+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
55+
* @param filePath Path to audio file to transcribe
56+
* @return Queued transcript
57+
* @throws IOException The file will be read and an IOException may be thrown.
58+
*/
59+
public Transcript submit(Path filePath) throws IOException {
60+
return submit(filePath, EMPTY_PARAMS);
61+
}
62+
63+
/**
64+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
65+
* @param filePath Path to audio file to transcribe
66+
* @return Queued transcript
67+
* @throws IOException The file will be read and an IOException may be thrown.
68+
*/
69+
public Transcript submit(Path filePath, TranscriptOptionalParams transcriptParams) throws IOException {
70+
UploadedFile uploadedFile = client.files().upload(filePath);
5071
return submit(uploadedFile.getUploadUrl(), transcriptParams);
5172
}
5273

74+
/**
75+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
76+
* @param file The file uploaded to AssemblyAI
77+
* @return Queued transcript
78+
*/
79+
public Transcript submit(UploadedFile file) {
80+
return submit(file.getUploadUrl(), EMPTY_PARAMS);
81+
}
82+
83+
/**
84+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
85+
* @param file The file uploaded to AssemblyAI
86+
* @return Queued transcript
87+
*/
88+
public Transcript submit(UploadedFile file, TranscriptOptionalParams transcriptParams) {
89+
return submit(file.getUploadUrl(), transcriptParams);
90+
}
91+
5392
/**
5493
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
5594
* @param url URL to the audio file to transcribe
@@ -107,6 +146,28 @@ public Transcript submit(String url, TranscriptOptionalParams transcriptParams)
107146
return super.submit(createTranscriptParams);
108147
}
109148

149+
/**
150+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
151+
* @param filePath Audio file to transcribe
152+
* @return A transcript with status "completed" or "error"
153+
* @throws IOException The file will be read and an IOException may be thrown.
154+
*/
155+
public Transcript transcribe(Path filePath) throws IOException {
156+
return transcribe(filePath, EMPTY_PARAMS);
157+
}
158+
159+
/**
160+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
161+
* @param filePath Audio file to transcribe
162+
* @param transcriptParams The parameters to transcribe an audio file.
163+
* @return A transcript with status "completed" or "error"
164+
* @throws IOException The file will be read and an IOException may be thrown.
165+
*/
166+
public Transcript transcribe(Path filePath, TranscriptOptionalParams transcriptParams) throws IOException {
167+
UploadedFile uploadedFile = client.files().upload(filePath);
168+
return transcribe(uploadedFile.getUploadUrl(), transcriptParams);
169+
}
170+
110171
/**
111172
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
112173
* @param file Audio file to transcribe
@@ -129,6 +190,26 @@ public Transcript transcribe(File file, TranscriptOptionalParams transcriptParam
129190
return transcribe(uploadedFile.getUploadUrl(), transcriptParams);
130191
}
131192

193+
/**
194+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
195+
* @param file The file uploaded to AssemblyAI
196+
* @return A transcript with status "completed" or "error"
197+
* @throws IOException The file will be read and an IOException may be thrown.
198+
*/
199+
public Transcript transcribe(UploadedFile file) throws IOException {
200+
return transcribe(file, EMPTY_PARAMS);
201+
}
202+
203+
/**
204+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
205+
* @param file The file uploaded to AssemblyAI
206+
* @param transcriptParams The parameters to transcribe an audio file.
207+
* @return A transcript with status "completed" or "error"
208+
*/
209+
public Transcript transcribe(UploadedFile file, TranscriptOptionalParams transcriptParams) {
210+
return transcribe(file.getUploadUrl(), transcriptParams);
211+
}
212+
132213
/**
133214
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
134215
* @param url URL to the audio file to transcribe
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.assemblyai.api.core;
22

33
public class Constants {
4-
public static final String SDK_VERSION = "2.1.4";
4+
public static final String SDK_VERSION = "2.2.0";
55
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.assemblyai.api.resources.files;
2+
3+
import com.assemblyai.api.core.*;
4+
import com.assemblyai.api.resources.files.types.UploadedFile;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
11+
public class ExtendedFilesClient extends FilesClient {
12+
public ExtendedFilesClient(ClientOptions clientOptions) {
13+
super(clientOptions);
14+
}
15+
16+
/**
17+
* Upload a media file to AssemblyAI's servers.
18+
*/
19+
public UploadedFile upload(File file) throws IOException {
20+
return upload(file, null);
21+
}
22+
23+
/**
24+
* Upload a media file to AssemblyAI's servers.
25+
*/
26+
public UploadedFile upload(File file, RequestOptions requestOptions) throws IOException {
27+
return upload(file.toPath(), requestOptions);
28+
}
29+
30+
/**
31+
* Upload a media file to AssemblyAI's servers.
32+
*/
33+
public UploadedFile upload(Path filePath) throws IOException {
34+
return upload(filePath, null);
35+
}
36+
37+
/**
38+
* Upload a media file to AssemblyAI's servers.
39+
*/
40+
public UploadedFile upload(Path filePath, RequestOptions requestOptions) throws IOException {
41+
return upload(Files.readAllBytes(filePath), requestOptions);
42+
}
43+
}

0 commit comments

Comments
 (0)