Skip to content

Commit

Permalink
update Transcriber to use BaseTranscriptCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Sep 19, 2023
1 parent 2da4f97 commit 1957253
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/main/java/com/assemblyai/api/Transcriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import com.assemblyai.api.core.Environment;
import com.assemblyai.api.resources.transcript.requests.CreateTranscriptParameters;
import com.assemblyai.api.types.BaseTranscriptCreate;
import com.assemblyai.api.types.SummaryModel;
import com.assemblyai.api.types.SummaryType;
import com.assemblyai.api.types.Transcript;
import com.assemblyai.api.types.TranscriptStatus;
import com.assemblyai.api.types.UploadResponseBody;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Optional;

public final class Transcriber {

Expand All @@ -21,19 +26,34 @@ private Transcriber(AssemblyAI client) {
* Transcribes an audio file whose location can be specified via a URL.
*/
public Transcript transcribe(String url, boolean poll) {
return transcribe(url, CreateTranscriptParameters.builder().build(), poll);
return transcribe(url, BaseTranscriptCreate.builder().build(), poll);
}

/**
* Transcribes an audio file whose location can be specified via a URL.
*/
public Transcript transcribe(String url, CreateTranscriptParameters transcriptRequest, boolean poll) {
Transcript transcriptResponse = this.client
.transcript()
.create(CreateTranscriptParameters.builder()
.from(transcriptRequest)
.audioUrl(url)
.build());
public Transcript transcribe(String url, BaseTranscriptCreate transcriptRequest, boolean poll) {
CreateTranscriptParameters createTranscript = CreateTranscriptParameters.builder()
.audioUrl(url)
.topics(transcriptRequest.getTopics())
.customTopics(transcriptRequest.getCustomTopics())
.summaryType(transcriptRequest.getSummaryType())
.summaryModel(transcriptRequest.getSummaryModel())
.summarization(transcriptRequest.getSummarization())
.speechThreshold(transcriptRequest.getSpeechThreshold())
.entityDetection(transcriptRequest.getEntityDetection())
.autoChapters(transcriptRequest.getAutoChapters())
.sentimentAnalysis(transcriptRequest.getSentimentAnalysis())
.autoChapters(transcriptRequest.getAutoChapters())
.entityDetection(transcriptRequest.getEntityDetection())
.speechThreshold(transcriptRequest.getSpeechThreshold())
.summarization(transcriptRequest.getSummarization())
.summaryModel(transcriptRequest.getSummaryModel())
.summaryType(transcriptRequest.getSummaryType())
.customTopics(transcriptRequest.getCustomTopics())
.topics(transcriptRequest.getTopics())
.build();
Transcript transcriptResponse = this.client.transcript().create(createTranscript);
if (poll) {
return awaitCompletion(transcriptResponse.getId());
}
Expand All @@ -44,13 +64,13 @@ public Transcript transcribe(String url, CreateTranscriptParameters transcriptRe
* Transcribes an audio file whose location can be specified via a filepath.
*/
public Transcript transcribe(File data, boolean poll) throws IOException {
return transcribe(data, CreateTranscriptParameters.builder().build(), poll);
return transcribe(data, BaseTranscriptCreate.builder().build(), poll);
}

/**
* Transcribes an audio file whose location can be specified via a filepath.
*/
public Transcript transcribe(File data, CreateTranscriptParameters transcriptRequest, boolean poll)
public Transcript transcribe(File data, BaseTranscriptCreate transcriptRequest, boolean poll)
throws IOException {
UploadResponseBody uploadResponse = this.client.files().upload(Files.readAllBytes(data.toPath()));
return transcribe(uploadResponse.getUploadUrl(), transcriptRequest, poll);
Expand All @@ -60,8 +80,7 @@ private Transcript awaitCompletion(String transcriptId) {
try {
while (true) {
Transcript transcript = this.client.transcript().get(transcriptId);
if (transcript.getStatus().isPresent()
&& transcript.getStatus().get().equals(TranscriptStatus.COMPLETED)) {
if (transcript.getStatus().equals(TranscriptStatus.COMPLETED)) {
return transcript;
}
Thread.sleep(1000);
Expand Down

0 comments on commit 1957253

Please sign in to comment.