Documentation
¶
Overview ¶
Package httpclient provides a typed Go client for consuming the go-whisper REST API.
Create a client with:
client, err := httpclient.New("http://localhost:8080/api/whisper")
if err != nil {
panic(err)
}
Then use the client to manage models and transcribe audio:
// List all models
models, err := client.ListModels(ctx)
// Get a specific model
model, err := client.GetModel(ctx, "tiny")
// Download a model with progress reporting
model, err := client.DownloadModel(ctx, "tiny", func(cur, total uint64) {
fmt.Printf("Progress: %d/%d bytes\n", cur, total)
})
// Delete a model
err := client.DeleteModel(ctx, "tiny")
// Transcribe audio from a file
file, _ := os.Open("audio.mp3")
result, err := client.Transcribe(ctx, "tiny", file)
// Transcribe with language specification
result, err := client.Transcribe(ctx, "tiny", file,
httpclient.WithLanguage("en"))
// Translate audio to English
result, err := client.Translate(ctx, "tiny", file)
// Get transcription in specific format
result, err := client.Transcribe(ctx, "tiny", file,
httpclient.WithFormat(httpclient.FormatVTT))
Index ¶
- type Client
- func (c *Client) DeleteModel(ctx context.Context, id string) error
- func (c *Client) DownloadModel(ctx context.Context, id string, progressFn func(cur, total uint64)) (*schema.Model, error)
- func (c *Client) GetModel(ctx context.Context, id string) (*schema.Model, error)
- func (c *Client) ListModels(ctx context.Context) ([]*schema.Model, error)
- func (c *Client) Transcribe(ctx context.Context, model string, r io.Reader, opts ...Opt) (*schema.Transcription, error)
- func (c *Client) Translate(ctx context.Context, model string, r io.Reader, opts ...Opt) (*schema.Transcription, error)
- type FormatType
- type Opt
- func WithDiarize(diarize bool) Opt
- func WithFilename(filename string) Opt
- func WithFormat(format FormatType) Opt
- func WithLanguage(language string) Opt
- func WithProgressCallback(callback func(*schema.Event) error) Opt
- func WithPrompt(prompt string) Opt
- func WithRequestOpts(opts ...client.RequestOpt) Opt
- func WithSegmentCallback(callback func(*schema.Segment) error) Opt
- func WithTemperature(temperature float64) Opt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is a whisper HTTP client that wraps the base HTTP client and provides typed methods for interacting with the whisper API.
func New ¶
New creates a new whisper HTTP client with the given base URL and options. The url parameter should point to the whisper API endpoint, e.g. "http://localhost:8080/api/whisper".
func (*Client) DeleteModel ¶
DeleteModel deletes the model identified by id.
func (*Client) DownloadModel ¶
func (c *Client) DownloadModel(ctx context.Context, id string, progressFn func(cur, total uint64)) (*schema.Model, error)
DownloadModel downloads a model with the given ID. The optional progress callback receives current and total bytes as the download progresses.
func (*Client) ListModels ¶
ListModels returns a list of all available models from the whisper API.
func (*Client) Transcribe ¶
func (c *Client) Transcribe(ctx context.Context, model string, r io.Reader, opts ...Opt) (*schema.Transcription, error)
Transcribe sends audio data for transcription. The audio parameter should be an io.Reader containing the audio data. The model parameter specifies which model to use. Use options to specify language and other parameters.
Example:
file, _ := os.Open("audio.mp3")
result, err := client.Transcribe(ctx, "tiny", file,
httpclient.WithLanguage("en"))
func (*Client) Translate ¶
func (c *Client) Translate(ctx context.Context, model string, r io.Reader, opts ...Opt) (*schema.Transcription, error)
Translate sends audio data for translation to English. The audio parameter should be an io.Reader containing the audio data. The model parameter specifies which model to use. Use options to specify other parameters.
Example:
file, _ := os.Open("audio.mp3")
result, err := client.Translate(ctx, "tiny", file,
httpclient.WithPrompt("technical content"))
type FormatType ¶
type FormatType string
FormatType represents the response format for transcription/translation requests
const ( FormatJSON FormatType = types.ContentTypeJSON FormatText FormatType = types.ContentTypeTextPlain FormatVTT FormatType = schema.ContentTypeVTT FormatSRT FormatType = schema.ContentTypeSRT )
type Opt ¶
type Opt func(*opt) error
Opt is an option to set on the client request.
func WithDiarize ¶
WithDiarize enables speaker diarization (identifying and separating speakers).
func WithFilename ¶
WithFilename sets an optional filename with extension for the audio file. Only the base filename (not the full path) will be used.
func WithFormat ¶
func WithFormat(format FormatType) Opt
WithFormat sets the Accept header to request a specific response format. Use the Format* constants (FormatJSON, FormatText, FormatVTT, FormatSRT).
func WithLanguage ¶
WithLanguage sets the language of the audio (two-letter code) for transcription. Use "auto" or empty string for automatic language detection.
func WithProgressCallback ¶ added in v0.0.36
WithProgressCallback sets a callback function to receive streaming events. This enables streaming support for downloads and other operations.
func WithPrompt ¶
WithPrompt sets an optional text prompt to guide the model's style.
func WithRequestOpts ¶ added in v0.0.37
func WithRequestOpts(opts ...client.RequestOpt) Opt
func WithSegmentCallback ¶ added in v0.0.36
WithSegmentCallback sets a callback function to receive segments as they are processed. This enables streaming support for transcription/translation.
func WithTemperature ¶
WithTemperature sets the sampling temperature for transcription. Valid range is [0, 1] inclusive, where 0 is deterministic and 1 is most random.