forked from openai/openai-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioTranscriptionsAsyncExample.java
More file actions
34 lines (28 loc) · 1.27 KB
/
Copy pathAudioTranscriptionsAsyncExample.java
File metadata and controls
34 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.openai.example;
import com.openai.client.OpenAIClientAsync;
import com.openai.client.okhttp.OpenAIOkHttpClientAsync;
import com.openai.models.audio.AudioModel;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import java.nio.file.Path;
import java.nio.file.Paths;
public final class AudioTranscriptionsAsyncExample {
private AudioTranscriptionsAsyncExample() {}
public static void main(String[] args) throws Exception {
// Configures using one of:
// - The `OPENAI_API_KEY` environment variable
// - The `OPENAI_BASE_URL` and `AZURE_OPENAI_KEY` environment variables
OpenAIClientAsync client = OpenAIOkHttpClientAsync.fromEnv();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
Path path = Paths.get(classloader.getResource("sports.wav").toURI());
TranscriptionCreateParams createParams = TranscriptionCreateParams.builder()
.file(path)
.model(AudioModel.WHISPER_1)
.build();
client.audio()
.transcriptions()
.create(createParams)
.thenAccept(response ->
System.out.println(response.asTranscription().text()))
.join();
}
}