@@ -27,8 +27,14 @@ const (
2727 AudioResponseFormatVTT AudioResponseFormat = "vtt"
2828)
2929
30+ type TranscriptionTimestampGranularity string
31+
32+ const (
33+ TranscriptionTimestampGranularityWord TranscriptionTimestampGranularity = "word"
34+ TranscriptionTimestampGranularitySegment TranscriptionTimestampGranularity = "segment"
35+ )
36+
3037// AudioRequest represents a request structure for audio API.
31- // ResponseFormat is not supported for now. We only return JSON text, which may be sufficient.
3238type AudioRequest struct {
3339 Model string
3440
@@ -38,10 +44,11 @@ type AudioRequest struct {
3844 // Reader is an optional io.Reader when you do not want to use an existing file.
3945 Reader io.Reader
4046
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.
4552}
4653
4754// AudioResponse represents a response structure for audio API.
@@ -62,6 +69,11 @@ type AudioResponse struct {
6269 NoSpeechProb float64 `json:"no_speech_prob"`
6370 Transient bool `json:"transient"`
6471 } `json:"segments"`
72+ Words []struct {
73+ Word string `json:"word"`
74+ Start float64 `json:"start"`
75+ End float64 `json:"end"`
76+ } `json:"words"`
6577 Text string `json:"text"`
6678
6779 httpHeader
@@ -179,6 +191,15 @@ func audioMultipartForm(request AudioRequest, b utils.FormBuilder) error {
179191 }
180192 }
181193
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+
182203 // Close the multipart writer
183204 return b .Close ()
184205}
0 commit comments