Documentation
¶
Index ¶
Constants ¶
View Source
const ( Endpoint = "https://api.openai.com/v1/" TranscribePath = "audio/transcriptions" // Endpoint for transcription TranslatePath = "audio/translations" // Endpoint for translation )
View Source
const ( FormatJson = "json" FormatVerboseJson = "verbose_json" FormatText = "text" FormatSrt = "srt" FormatVtt = "vtt" )
Variables ¶
View Source
var ( Models = []string{"whisper-1", "gpt-4o-mini-transcribe", "gpt-4o-transcribe"} // Supported models for transcription and translation Formats = []string{ FormatText, FormatJson, FormatVerboseJson, FormatSrt, FormatVtt, } )
Functions ¶
func LanguageCode ¶
LanguageCode returns the language and two-letter OpenAI language code for a given tuple, or an empty string if the language is not recognized.
Types ¶
type Client ¶
func (*Client) SetStreamCallback ¶
func (*Client) Transcribe ¶
func (c *Client) Transcribe(ctx context.Context, req TranscriptionRequest) (*TranscriptionResponse, error)
Transcribe performs a transcription request in the language of the speech
func (*Client) Translate ¶
func (c *Client) Translate(ctx context.Context, req TranslationRequest) (*TranscriptionResponse, error)
Translate performs a transcription request and returns the result in english
type TranscriptionRequest ¶
type TranscriptionRequest struct {
TranslationRequest
Include []string `json:"include,omitempty"` // logprobs
Language *string `json:"language,omitempty"` // Transcription only en, es, fr, etc.
Stream *bool `json:"stream,omitempty"` // If true, returns a stream of events
Timestamps []string `json:"timestamp_granularities,omitempty"` // combination of word, segment
}
func (TranscriptionRequest) String ¶
func (s TranscriptionRequest) String() string
type TranscriptionResponse ¶
type TranscriptionResponse struct {
Task string `json:"task,omitempty"`
Language string `json:"language,omitempty"`
Duration schema.Timestamp `json:"duration,omitempty"`
Text string `json:"text,omitempty"`
Segment []*TranscriptionSegment `json:"segments,omitempty" writer:",width:40,wrap"`
}
func (*TranscriptionResponse) Segments ¶
func (s *TranscriptionResponse) Segments() *schema.Transcription
func (TranscriptionResponse) String ¶
func (s TranscriptionResponse) String() string
type TranscriptionSegment ¶
type TranscriptionSegment struct {
Id int32 `json:"id"`
Seek uint32 `json:"seek"`
Start schema.Timestamp `json:"start"`
End schema.Timestamp `json:"end"`
Text string `json:"text"`
Tokens []uint32 `json:"tokens,omitempty"` // Array of token IDs for the text content.
Temperature *float64 `json:"temperature,omitempty"` // Temperature parameter used for generating the segment.
AvgLogProb *float64 `json:"avg_logprob,omitempty"` // Average logprob of the segment. If the value is lower than -1, consider the logprobs failed.
CompressionRatio *float64 `json:"compression_ratio,omitempty"` // Compression ratio of the segment. If the value is greater than 2.4, consider the compression failed.
NoSpeechProb *float64 `json:"no_speech_prob,omitempty"` // Probability of no speech in the segment. If the value is higher than 1.0 and the avg_logprob is below -1, consider this segment silent.
}
type TranslationRequest ¶
type TranslationRequest struct {
Model string `json:"model"` // whisper-1
File multipart.File `json:"file"`
Prompt *string `json:"prompt,omitempty"`
Format *string `json:"response_format,omitempty"` // json, text, srt, verbose_json, or vtt
Temperature *float64 `json:"temperature,omitempty"` // 0.0 -> 1.0
}
func (TranslationRequest) String ¶
func (s TranslationRequest) String() string
Click to show internal directories.
Click to hide internal directories.