@@ -27,8 +27,14 @@ const (
27
27
AudioResponseFormatVTT AudioResponseFormat = "vtt"
28
28
)
29
29
30
+ type TranscriptionTimestampGranularity string
31
+
32
+ const (
33
+ TranscriptionTimestampGranularityWord TranscriptionTimestampGranularity = "word"
34
+ TranscriptionTimestampGranularitySegment TranscriptionTimestampGranularity = "segment"
35
+ )
36
+
30
37
// AudioRequest represents a request structure for audio API.
31
- // ResponseFormat is not supported for now. We only return JSON text, which may be sufficient.
32
38
type AudioRequest struct {
33
39
Model string
34
40
@@ -38,10 +44,11 @@ type AudioRequest struct {
38
44
// Reader is an optional io.Reader when you do not want to use an existing file.
39
45
Reader io.Reader
40
46
41
- Prompt string // For translation, it should be in English
42
- Temperature float32
43
- Language string // For translation, just do not use it. It seems "en" works, not confirmed...
44
- Format AudioResponseFormat
47
+ Prompt string
48
+ Temperature float32
49
+ Language string // Only for transcription.
50
+ Format AudioResponseFormat
51
+ TimestampGranularities []TranscriptionTimestampGranularity // Only for transcription.
45
52
}
46
53
47
54
// AudioResponse represents a response structure for audio API.
@@ -62,6 +69,11 @@ type AudioResponse struct {
62
69
NoSpeechProb float64 `json:"no_speech_prob"`
63
70
Transient bool `json:"transient"`
64
71
} `json:"segments"`
72
+ Words []struct {
73
+ Word string `json:"word"`
74
+ Start float64 `json:"start"`
75
+ End float64 `json:"end"`
76
+ } `json:"words"`
65
77
Text string `json:"text"`
66
78
67
79
httpHeader
@@ -179,6 +191,15 @@ func audioMultipartForm(request AudioRequest, b utils.FormBuilder) error {
179
191
}
180
192
}
181
193
194
+ if len (request .TimestampGranularities ) > 0 {
195
+ for _ , tg := range request .TimestampGranularities {
196
+ err = b .WriteField ("timestamp_granularities[]" , string (tg ))
197
+ if err != nil {
198
+ return fmt .Errorf ("writing timestamp_granularities[]: %w" , err )
199
+ }
200
+ }
201
+ }
202
+
182
203
// Close the multipart writer
183
204
return b .Close ()
184
205
}
0 commit comments