httpclient

package
v0.0.39 Latest Latest
Warning

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

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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*client.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

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

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

func (c *Client) DeleteModel(ctx context.Context, id string) error

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) GetModel

func (c *Client) GetModel(ctx context.Context, id string) (*schema.Model, error)

GetModel retrieves a specific model by its ID.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]*schema.Model, error)

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

type Opt

type Opt func(*opt) error

Opt is an option to set on the client request.

func WithDiarize

func WithDiarize(diarize bool) Opt

WithDiarize enables speaker diarization (identifying and separating speakers).

func WithFilename

func WithFilename(filename string) Opt

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

func WithLanguage(language string) Opt

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

func WithProgressCallback(callback func(*schema.Event) error) Opt

WithProgressCallback sets a callback function to receive streaming events. This enables streaming support for downloads and other operations.

func WithPrompt

func WithPrompt(prompt string) Opt

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

func WithSegmentCallback(callback func(*schema.Segment) error) Opt

WithSegmentCallback sets a callback function to receive segments as they are processed. This enables streaming support for transcription/translation.

func WithTemperature

func WithTemperature(temperature float64) Opt

WithTemperature sets the sampling temperature for transcription. Valid range is [0, 1] inclusive, where 0 is deterministic and 1 is most random.

Jump to

Keyboard shortcuts

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