-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
112 lines (98 loc) · 3.56 KB
/
code.power
File metadata and controls
112 lines (98 loc) · 3.56 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Transcribes audio into the input language.
* API Ref: https://platform.openai.com/docs/api-reference/audio/create
*
* @param string $file The audio file to transcribe. Formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm (required).
* @param string|null $prompt An optional text to guide the model's style (optional).
* @param string|null $responseFormat The format of the transcript output. Options: json, text, srt, verbose_json, or vtt (optional).
* @param float|null $temperature The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic (optional).
* @param string|null $language The language of the input audio (optional).
* @param string $model ID of the model to use. Only "whisper-1" is currently available.
*
* @return object|null
* @since 3.2.0
**/
public function transcribe(
string $file,
?string $prompt = null,
?string $responseFormat = null,
?float $temperature = null,
?string $language = null,
string $model = 'whisper-1'
): ?object
{
// Build the request path.
$path = "/audio/transcriptions";
// Set the request data.
$data = new \stdClass();
$data->file = $file;
if ($prompt !== null)
{
$data->prompt = $prompt;
}
if ($responseFormat !== null)
{
$data->response_format = $responseFormat;
}
if ($temperature !== null)
{
$data->temperature = $temperature;
}
if ($language !== null)
{
$data->language = $language;
}
$data->model = $model;
// Send the post request.
return $this->response->get(
$this->http->post(
$this->uri->get($path), json_encode($data), ['Content-Type' => 'multipart/form-data']
)
);
}
/**
* Translate an audio file into English.
* API Ref: https://platform.openai.com/docs/api-reference/audio/create
*
* @param string $file The the audio file. Formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm (required).
* @param string|null $prompt An optional text to guide the model's style or continue a previous audio segment. The prompt should be in English (optional).
* @param string|null $responseFormat The format of the transcript output. Options: json, text, srt, verbose_json, or vtt (optional).
* @param float|null $temperature The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic (optional).
* @param string $model ID of the model to use. Only "whisper-1" is currently available.
*
* @return object|null
* @since 3.2.0
**/
public function translation(
string $file,
?string $prompt = null,
?string $responseFormat = null,
?float $temperature = null,
string $model = 'whisper-1'
): ?object
{
// Build the request path.
$path = "/audio/translations";
// Set the data.
$data = new \stdClass();
$data->file = $file;
if ($prompt !== null)
{
$data->prompt = $prompt;
}
if ($responseFormat !== null)
{
$data->response_format = $responseFormat;
}
if ($temperature !== null)
{
$data->temperature = $temperature;
}
$data->model = $model;
// Send the post request.
return $this->response->get(
$this->http->post(
$this->uri->get($path), json_encode($data), ['Content-Type' => 'multipart/form-data']
)
);
}