This repository has been archived by the owner on May 7, 2024. It is now read-only.
/
whisper.go
45 lines (43 loc) · 1.65 KB
/
whisper.go
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
package openai
type AudioTranscriptionResponse struct {
Text string `json:"text"`
}
// AudioTranscription performs audio transcription using the specified template.
//
// Example of use:
// client := openai.New("your-api-key")
// model := "model_name"
// filename := "audio.mp3"
// audioFilePath := "./path/to/audio.mp3"
//
// resp, err := client.AudioTranscription(&openai.WhisperParams{
// Model:"whisper-1",
// Filename: filename,
// AudioFilePath: filePath,
// })
//
// if err != nil {
// log.Fatalf("Error transcribing audio: %v", err)
// }
//
// fmt.Printf("Audio transcription: %s\n", resp.Text)
//
// WhisperParams:
// - Model: Name of the model to be used for audio transcription. See documentation for supported models: https://platform.openai.com/docs/models/model-endpoint-compatibility
// - Filename: Name of the audio file.
// - AudioFilePath: Path of the audio file on the local file system.
//
// Returns:
// A pointer to an AudioTranscriptionResponse containing the audio transcription and possible errors found.
//
// Possible errors:
// - If an error occurs when opening the audio file.
// - If an error occurs while creating the multipart form.
// - If an error occurs while copying the file contents to the request body.
// - If an error occurs when creating the HTTP request.
// - If an error occurs when making the HTTP request to the OpenAI service.
// - If an error occurs while decoding the JSON response from the OpenAI service.
// - If the HTTP response status code is not 200 (OK).
func (oc *Client) AudioTranscription(requestParams *WhisperParams) (*AudioTranscriptionResponse, error) {
return requestParams.Response(oc)
}