Skip to content

Commit

Permalink
the http client supports polling the transcriber apis
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Dec 4, 2023
1 parent ead210f commit 23aa4b2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Specify files that shouldn't be modified by Fern

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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The SDK exports a vanilla HTTP client, `AssemblyAI`. You can
use this to call into each of our API endpoints and get typed
responses back.

```typescript
```java
import com.assemblyai.api.AssemblyAI;

AssemblyAI aai = AssemblyAI.builder()
Expand All @@ -60,7 +60,7 @@ When the API returns a non-success status code (4xx or 5xx response),
a subclass of [ApiError](src/main/java/com/assemblyai/api/core/ApiError.java)
will be thrown:

```ts
```java
import com.assemblyai.api.core.ApiError;

try {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/assemblyai/api/AssemblyAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AssemblyAI {

protected final Supplier<FilesClient> filesClient;

protected final Supplier<TranscriptClient> transcriptClient;
protected final Supplier<PollingTranscriptClient> transcriptClient;

protected final Supplier<RealtimeClient> realtimeClient;

Expand All @@ -25,7 +25,8 @@ public class AssemblyAI {
public AssemblyAI(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.filesClient = Suppliers.memoize(() -> new FilesClient(clientOptions));
this.transcriptClient = Suppliers.memoize(() -> new TranscriptClient(clientOptions));
this.transcriptClient = Suppliers.memoize(() ->
new PollingTranscriptClient(clientOptions, new Transcriber(this)));
this.realtimeClient = Suppliers.memoize(() -> new RealtimeClient(clientOptions));
this.lemurClient = Suppliers.memoize(() -> new LemurClient(clientOptions));
}
Expand All @@ -34,7 +35,7 @@ public FilesClient files() {
return this.filesClient.get();
}

public TranscriptClient transcript() {
public PollingTranscriptClient transcript() {
return this.transcriptClient.get();
}

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/assemblyai/api/PollingTranscriptClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.assemblyai.api;

import com.assemblyai.api.core.ClientOptions;
import com.assemblyai.api.resources.transcript.TranscriptClient;
import com.assemblyai.api.resources.transcript.requests.CreateTranscriptParameters;
import com.assemblyai.api.types.Transcript;

public class PollingTranscriptClient extends TranscriptClient {

private final Transcriber transcriber;

public PollingTranscriptClient(ClientOptions clientOptions, Transcriber transcriber) {
super(clientOptions);
this.transcriber = transcriber;
}

/**
* Get the transcript resource. The transcript is ready when the &quot;status&quot; is &quot;completed&quot;.
*/
public Transcript create(CreateTranscriptParameters request, boolean poll) {
return transcriber.transcribe(request.getAudioUrl(), request, poll);
}

}
8 changes: 6 additions & 2 deletions src/main/java/com/assemblyai/api/Transcriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.assemblyai.api.core.Environment;
import com.assemblyai.api.resources.transcript.requests.CreateTranscriptParameters;
import com.assemblyai.api.types.CreateTranscriptOptionalParameters;
import com.assemblyai.api.types.ICreateTranscriptOptionalParameters;
import com.assemblyai.api.types.Transcript;
import com.assemblyai.api.types.TranscriptStatus;
import com.assemblyai.api.types.UploadedFile;
Expand All @@ -14,7 +15,7 @@ public final class Transcriber {

private final AssemblyAI client;

private Transcriber(AssemblyAI client) {
Transcriber(AssemblyAI client) {
this.client = client;
}

Expand All @@ -37,7 +38,10 @@ public Transcript transcribe(String url, CreateTranscriptOptionalParameters tran
/**
* Transcribes an audio file whose location can be specified via a URL.
*/
public Transcript transcribe(String url, CreateTranscriptOptionalParameters transcriptRequest, boolean poll) {
public Transcript transcribe(
String url,
ICreateTranscriptOptionalParameters transcriptRequest,
boolean poll) {
CreateTranscriptParameters createTranscript = CreateTranscriptParameters.builder()
.audioUrl(url)
.languageCode(transcriptRequest.getLanguageCode())
Expand Down

0 comments on commit 23aa4b2

Please sign in to comment.