Skip to content

Commit

Permalink
audio: add items to AudioResponseFormat enum (#382)
Browse files Browse the repository at this point in the history
* audio: add items to AudioResponseFormat enum

* audio: expand AudioResponse struct to accommodate verbose json response

---------

Co-authored-by: Roman Zubov <rzubov@aintsys.com>
  • Loading branch information
romazu and Roman Zubov committed Jun 16, 2023
1 parent ac25f31 commit f0770cf
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions audio.go
Expand Up @@ -20,9 +20,11 @@ const (
type AudioResponseFormat string

const (
AudioResponseFormatJSON AudioResponseFormat = "json"
AudioResponseFormatSRT AudioResponseFormat = "srt"
AudioResponseFormatVTT AudioResponseFormat = "vtt"
AudioResponseFormatJSON AudioResponseFormat = "json"
AudioResponseFormatText AudioResponseFormat = "text"
AudioResponseFormatSRT AudioResponseFormat = "srt"
AudioResponseFormatVerboseJSON AudioResponseFormat = "verbose_json"
AudioResponseFormatVTT AudioResponseFormat = "vtt"
)

// AudioRequest represents a request structure for audio API.
Expand All @@ -44,6 +46,22 @@ type AudioRequest struct {

// AudioResponse represents a response structure for audio API.
type AudioResponse struct {
Task string `json:"task"`
Language string `json:"language"`
Duration float64 `json:"duration"`
Segments []struct {
ID int `json:"id"`
Seek int `json:"seek"`
Start float64 `json:"start"`
End float64 `json:"end"`
Text string `json:"text"`
Tokens []int `json:"tokens"`
Temperature float64 `json:"temperature"`
AvgLogprob float64 `json:"avg_logprob"`
CompressionRatio float64 `json:"compression_ratio"`
NoSpeechProb float64 `json:"no_speech_prob"`
Transient bool `json:"transient"`
} `json:"segments"`
Text string `json:"text"`
}

Expand Down Expand Up @@ -96,7 +114,7 @@ func (c *Client) callAudioAPI(

// HasJSONResponse returns true if the response format is JSON.
func (r AudioRequest) HasJSONResponse() bool {
return r.Format == "" || r.Format == AudioResponseFormatJSON
return r.Format == "" || r.Format == AudioResponseFormatJSON || r.Format == AudioResponseFormatVerboseJSON
}

// audioMultipartForm creates a form with audio file contents and the name of the model to use for
Expand Down

0 comments on commit f0770cf

Please sign in to comment.