openai

package
v0.0.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

func LanguageCode(language string) (string, string)

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

type Client struct {
	*client.Client
	// contains filtered or unexported fields
}

func New

func New(apikey string, opts ...client.ClientOpt) (*Client, error)

New creates a new client, with the elevenslabs token

func (*Client) SetStreamCallback

func (c *Client) SetStreamCallback(fn func(schema.Event))

func (*Client) Transcribe

Transcribe performs a transcription request in the language of the speech

func (*Client) Translate

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 (TranscriptionResponse) String

func (s TranscriptionResponse) String() string

func (*TranscriptionResponse) Unmarshal

func (s *TranscriptionResponse) Unmarshal(header http.Header, r io.Reader) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL