Skip to content

Commit cefda91

Browse files
authored
Merge pull request #124 from AssemblyAI/fern-bot/10-03-2024-0606PM
🌿 Fern Regeneration -- October 3, 2024
2 parents 2b44044 + a1bc3af commit cefda91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+576
-268
lines changed

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.3.1'
50+
version = '3.0.0'
5151
from components.java
5252
pom {
5353
scm {

gradle/wrapper/gradle-wrapper.jar

79 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

sample-app/src/main/java/sample/App.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static void main(String... args) throws IOException, InterruptedException
128128
System.out.println("Delete transcript. " + transcript);
129129

130130
File file = new File("sample-app/src/main/resources/nZP7pb_t4oA.mp3");
131-
UploadedFile uploadedFile = client.files().upload(Files.readAllBytes(file.toPath()));
131+
UploadedFile uploadedFile = client.files().upload(file);
132132
System.out.println("Uploaded file" + uploadedFile);
133133

134134
transcript = client.transcripts().submit(TranscriptParams.builder()

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

+104-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import java.io.File;
1515
import java.io.IOException;
16-
import java.nio.file.Files;
16+
import java.io.InputStream;
1717
import java.nio.file.Path;
1818
import java.util.List;
1919

@@ -29,6 +29,58 @@ public PollingTranscriptsClient(ClientOptions clientOptions, AssemblyAI client)
2929
this.client = client;
3030
}
3131

32+
/**
33+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
34+
*
35+
* @param file Audio file to transcribe
36+
* @return Queued transcript
37+
* @throws IOException The file will be read and an IOException may be thrown.
38+
*/
39+
public Transcript submit(InputStream file) throws IOException {
40+
return submit(file, EMPTY_PARAMS, null);
41+
}
42+
43+
/**
44+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
45+
*
46+
* @param file Audio file to transcribe
47+
* @param requestOptions The HTTP request options
48+
* @return Queued transcript
49+
* @throws IOException The file will be read and an IOException may be thrown.
50+
*/
51+
public Transcript submit(InputStream file, RequestOptions requestOptions) throws IOException {
52+
return submit(file, EMPTY_PARAMS, requestOptions);
53+
}
54+
55+
/**
56+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
57+
*
58+
* @param file Audio file to transcribe
59+
* @param transcriptParams The parameters to transcribe an audio file.
60+
* @return Queued transcript
61+
* @throws IOException The file will be read and an IOException may be thrown.
62+
*/
63+
public Transcript submit(InputStream file, TranscriptOptionalParams transcriptParams) throws IOException {
64+
return submit(file, transcriptParams, null);
65+
}
66+
67+
/**
68+
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
69+
*
70+
* @param file Audio file to transcribe
71+
* @param transcriptParams The parameters to transcribe an audio file.
72+
* @param requestOptions The HTTP request options
73+
* @return Queued transcript
74+
*/
75+
public Transcript submit(
76+
InputStream file,
77+
TranscriptOptionalParams transcriptParams,
78+
RequestOptions requestOptions
79+
) {
80+
UploadedFile uploadedFile = client.files().upload(file, requestOptions);
81+
return submit(uploadedFile.getUploadUrl(), transcriptParams, requestOptions);
82+
}
83+
3284
/**
3385
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
3486
*
@@ -245,6 +297,56 @@ public Transcript submit(String url, TranscriptOptionalParams transcriptParams,
245297
return super.submit(fullTranscriptParams, requestOptions);
246298
}
247299

300+
/**
301+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
302+
*
303+
* @param file Audio file to transcribe
304+
* @return A transcript with status "completed" or "error"
305+
* @throws IOException The file will be read and an IOException may be thrown.
306+
*/
307+
public Transcript transcribe(InputStream file) throws IOException {
308+
return transcribe(file, EMPTY_PARAMS, null);
309+
}
310+
311+
/**
312+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
313+
*
314+
* @param file Audio file to transcribe
315+
* @param requestOptions The HTTP request options
316+
* @return A transcript with status "completed" or "error"
317+
* @throws IOException The file will be read and an IOException may be thrown.
318+
*/
319+
public Transcript transcribe(InputStream file, RequestOptions requestOptions) throws IOException {
320+
return transcribe(file, EMPTY_PARAMS, requestOptions);
321+
}
322+
323+
/**
324+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
325+
*
326+
* @param file Audio file to transcribe
327+
* @param transcriptParams The parameters to transcribe an audio file.
328+
* @return A transcript with status "completed" or "error"
329+
* @throws IOException The file will be read and an IOException may be thrown.
330+
*/
331+
public Transcript transcribe(InputStream file, TranscriptOptionalParams transcriptParams) throws IOException {
332+
UploadedFile uploadedFile = client.files().upload(file);
333+
return transcribe(uploadedFile.getUploadUrl(), transcriptParams, null);
334+
}
335+
336+
/**
337+
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
338+
*
339+
* @param file Audio file to transcribe
340+
* @param transcriptParams The parameters to transcribe an audio file.
341+
* @param requestOptions The HTTP request options
342+
* @return A transcript with status "completed" or "error"
343+
* @throws IOException The file will be read and an IOException may be thrown.
344+
*/
345+
public Transcript transcribe(InputStream file, TranscriptOptionalParams transcriptParams, RequestOptions requestOptions) throws IOException {
346+
UploadedFile uploadedFile = client.files().upload(file, requestOptions);
347+
return transcribe(uploadedFile.getUploadUrl(), transcriptParams, requestOptions);
348+
}
349+
248350
/**
249351
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
250352
*
@@ -344,7 +446,7 @@ public Transcript transcribe(
344446
TranscriptOptionalParams transcriptParams,
345447
RequestOptions requestOptions
346448
) throws IOException {
347-
UploadedFile uploadedFile = client.files().upload(Files.readAllBytes(file.toPath()), requestOptions);
449+
UploadedFile uploadedFile = client.files().upload(file, requestOptions);
348450
return transcribe(uploadedFile.getUploadUrl(), transcriptParams, requestOptions);
349451
}
350452

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.3.1";
4+
public static final String SDK_VERSION = "3.0.0";
55
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.assemblyai.api.core;
5+
6+
import java.io.InputStream;
7+
import java.util.Objects;
8+
import okhttp3.MediaType;
9+
import okhttp3.RequestBody;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
/**
13+
* Represents a file stream with associated metadata for file uploads.
14+
*/
15+
public class FileStream {
16+
private final InputStream inputStream;
17+
private final String fileName;
18+
private final MediaType contentType;
19+
20+
/**
21+
* Constructs a FileStream with the given input stream and optional metadata.
22+
*
23+
* @param inputStream The input stream of the file content. Must not be null.
24+
* @param fileName The name of the file, or null if unknown.
25+
* @param contentType The MIME type of the file content, or null if unknown.
26+
* @throws NullPointerException if inputStream is null
27+
*/
28+
public FileStream(InputStream inputStream, @Nullable String fileName, @Nullable MediaType contentType) {
29+
this.inputStream = Objects.requireNonNull(inputStream, "Input stream cannot be null");
30+
this.fileName = fileName;
31+
this.contentType = contentType;
32+
}
33+
34+
public FileStream(InputStream inputStream) {
35+
this(inputStream, null, null);
36+
}
37+
38+
public InputStream getInputStream() {
39+
return inputStream;
40+
}
41+
42+
@Nullable
43+
public String getFileName() {
44+
return fileName;
45+
}
46+
47+
@Nullable
48+
public MediaType getContentType() {
49+
return contentType;
50+
}
51+
52+
/**
53+
* Creates a RequestBody suitable for use with OkHttp client.
54+
*
55+
* @return A RequestBody instance representing this file stream.
56+
*/
57+
public RequestBody toRequestBody() {
58+
return new InputStreamRequestBody(contentType, inputStream);
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.assemblyai.api.core;
5+
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.util.Objects;
9+
import okhttp3.MediaType;
10+
import okhttp3.RequestBody;
11+
import okhttp3.internal.Util;
12+
import okio.BufferedSink;
13+
import okio.Okio;
14+
import okio.Source;
15+
import org.jetbrains.annotations.Nullable;
16+
17+
/**
18+
* A custom implementation of OkHttp's RequestBody that wraps an InputStream.
19+
* This class allows streaming of data from an InputStream directly to an HTTP request body,
20+
* which is useful for file uploads or sending large amounts of data without loading it all into memory.
21+
*/
22+
public class InputStreamRequestBody extends RequestBody {
23+
private final InputStream inputStream;
24+
private final MediaType contentType;
25+
26+
/**
27+
* Constructs an InputStreamRequestBody with the specified content type and input stream.
28+
*
29+
* @param contentType the MediaType of the content, or null if not known
30+
* @param inputStream the InputStream containing the data to be sent
31+
* @throws NullPointerException if inputStream is null
32+
*/
33+
public InputStreamRequestBody(@Nullable MediaType contentType, InputStream inputStream) {
34+
this.contentType = contentType;
35+
this.inputStream = Objects.requireNonNull(inputStream, "inputStream == null");
36+
}
37+
38+
/**
39+
* Returns the content type of this request body.
40+
*
41+
* @return the MediaType of the content, or null if not specified
42+
*/
43+
@Nullable
44+
@Override
45+
public MediaType contentType() {
46+
return contentType;
47+
}
48+
49+
/**
50+
* Returns the content length of this request body, if known.
51+
* This method attempts to determine the length using the InputStream's available() method,
52+
* which may not always accurately reflect the total length of the stream.
53+
*
54+
* @return the content length, or -1 if the length is unknown
55+
* @throws IOException if an I/O error occurs
56+
*/
57+
@Override
58+
public long contentLength() throws IOException {
59+
return inputStream.available() == 0 ? -1 : inputStream.available();
60+
}
61+
62+
/**
63+
* Writes the content of the InputStream to the given BufferedSink.
64+
* This method is responsible for transferring the data from the InputStream to the network request.
65+
*
66+
* @param sink the BufferedSink to write the content to
67+
* @throws IOException if an I/O error occurs during writing
68+
*/
69+
@Override
70+
public void writeTo(BufferedSink sink) throws IOException {
71+
Source source = null;
72+
try {
73+
source = Okio.source(inputStream);
74+
sink.writeAll(source);
75+
} finally {
76+
Util.closeQuietly(Objects.requireNonNull(source));
77+
}
78+
}
79+
}

src/main/java/com/assemblyai/api/resources/files/ExtendedFilesClient.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.nio.file.Files;
99
import java.nio.file.Path;
10+
import java.nio.file.StandardOpenOption;
1011

1112
public class ExtendedFilesClient extends FilesClient {
1213
public ExtendedFilesClient(ClientOptions clientOptions) {
@@ -38,6 +39,6 @@ public UploadedFile upload(Path filePath) throws IOException {
3839
* Upload a media file to AssemblyAI's servers.
3940
*/
4041
public UploadedFile upload(Path filePath, RequestOptions requestOptions) throws IOException {
41-
return upload(Files.readAllBytes(filePath), requestOptions);
42+
return upload(Files.newInputStream(filePath, StandardOpenOption.READ), requestOptions);
4243
}
4344
}

src/main/java/com/assemblyai/api/resources/files/FilesClient.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.assemblyai.api.core.AssemblyAIApiException;
77
import com.assemblyai.api.core.AssemblyAIException;
88
import com.assemblyai.api.core.ClientOptions;
9+
import com.assemblyai.api.core.InputStreamRequestBody;
910
import com.assemblyai.api.core.ObjectMappers;
1011
import com.assemblyai.api.core.RequestOptions;
1112
import com.assemblyai.api.errors.BadRequestError;
@@ -18,9 +19,12 @@
1819
import com.assemblyai.api.resources.files.types.UploadedFile;
1920
import com.assemblyai.api.types.Error;
2021
import com.fasterxml.jackson.core.JsonProcessingException;
22+
import java.io.ByteArrayInputStream;
2123
import java.io.IOException;
24+
import java.io.InputStream;
2225
import okhttp3.Headers;
2326
import okhttp3.HttpUrl;
27+
import okhttp3.MediaType;
2428
import okhttp3.OkHttpClient;
2529
import okhttp3.Request;
2630
import okhttp3.RequestBody;
@@ -37,24 +41,23 @@ public FilesClient(ClientOptions clientOptions) {
3741
/**
3842
* Upload a media file to AssemblyAI's servers.
3943
*/
40-
public UploadedFile upload(byte[] request) {
44+
public UploadedFile upload(InputStream request) {
4145
return upload(request, null);
4246
}
4347

4448
/**
4549
* Upload a media file to AssemblyAI's servers.
4650
*/
47-
public UploadedFile upload(byte[] request, RequestOptions requestOptions) {
51+
public UploadedFile upload(InputStream request, RequestOptions requestOptions) {
4852
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
4953
.newBuilder()
5054
.addPathSegments("v2/upload")
5155
.build();
52-
RequestBody body = RequestBody.create(request);
56+
RequestBody body = new InputStreamRequestBody(MediaType.parse("application/octet-stream"), request);
5357
Request okhttpRequest = new Request.Builder()
5458
.url(httpUrl)
5559
.method("POST", body)
5660
.headers(Headers.of(clientOptions.headers(requestOptions)))
57-
.addHeader("Content-Type", "application/octet-stream")
5861
.build();
5962
OkHttpClient client = clientOptions.httpClient();
6063
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
@@ -99,4 +102,18 @@ public UploadedFile upload(byte[] request, RequestOptions requestOptions) {
99102
throw new AssemblyAIException("Network error executing HTTP request", e);
100103
}
101104
}
105+
106+
/**
107+
* Upload a media file to AssemblyAI's servers.
108+
*/
109+
public UploadedFile upload(byte[] request) {
110+
return upload(new ByteArrayInputStream(request));
111+
}
112+
113+
/**
114+
* Upload a media file to AssemblyAI's servers.
115+
*/
116+
public UploadedFile upload(byte[] request, RequestOptions requestOptions) {
117+
return upload(new ByteArrayInputStream(request), requestOptions);
118+
}
102119
}

0 commit comments

Comments
 (0)