whisper

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: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Sample Rate
	SampleRate = whisper.SampleRate
)

Variables

This section is empty.

Functions

func WriteSegmentSrt added in v0.0.26

func WriteSegmentSrt(w io.Writer, seg *schema.Segment)

func WriteSegmentText added in v0.0.26

func WriteSegmentText(w io.Writer, seg *schema.Segment)

func WriteSegmentVtt added in v0.0.26

func WriteSegmentVtt(w io.Writer, seg *schema.Segment)

Types

type LogFn added in v0.0.9

type LogFn func(string)

type Manager added in v0.0.26

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager provides a global whisper manager with automatic cleanup

func New

func New(path string, opt ...Opt) (*Manager, error)

New initializes the global whisper manager with the specified path to the models directory and optional parameters. Returns an error if the manager is already initialized.

func (*Manager) Close added in v0.0.26

func (m *Manager) Close() error

Close closes the whisper manager and releases all resources. It is safe to call multiple times.

func (*Manager) DeleteModelById added in v0.0.26

func (m *Manager) DeleteModelById(id string) error

DeleteModelById deletes a model by its id

func (*Manager) DownloadModel added in v0.0.26

func (m *Manager) DownloadModel(ctx context.Context, path string, fn func(curBytes, totalBytes uint64)) (*schema.Model, error)

DownloadModel downloads a model by path, where the directory is the root of the model within the models directory. The model is returned immediately if it already exists in the store

func (*Manager) GetModelById added in v0.0.26

func (m *Manager) GetModelById(id string) *schema.Model

GetModelById returns a model by its Id, returns nil if the model does not exist

func (*Manager) ListModels added in v0.0.26

func (m *Manager) ListModels() []*schema.Model

ListModels returns all models in the models directory

func (*Manager) WithModel added in v0.0.26

func (m *Manager) WithModel(model *schema.Model, fn func(task *Task) error, opts ...Opt) error

WithModel gets a task for the specified model and executes the function. The task is automatically returned to the pool when done.

type NewSegmentFunc added in v0.0.26

type NewSegmentFunc func(*schema.Segment)

Callback for new segments during the transcription process

type Opt added in v0.0.9

type Opt func(*opts) error

func OptDebug added in v0.0.9

func OptDebug() Opt

Set debugging

func OptLog added in v0.0.9

func OptLog(fn LogFn) Opt

Set logging function

func OptMaxConcurrent added in v0.0.9

func OptMaxConcurrent(v int) Opt

Set maximum number of concurrent tasks

func OptNoGPU added in v0.0.9

func OptNoGPU() Opt

Disable GPU acceleration

func OptTracer added in v0.0.36

func OptTracer(tracer trace.Tracer) Opt

Add OTEL Tracer

type Task added in v0.0.26

type Task struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Task is used for running the transcription or translation

func NewTask added in v0.0.26

func NewTask() *Task

NewTask creates a new task object

func (*Task) CanTranslate added in v0.0.26

func (t *Task) CanTranslate() bool

Model is multilingual and can translate

func (*Task) Close added in v0.0.26

func (t *Task) Close() error

Close the task and release all resources. The task itself can be re-used by calling Init again

func (*Task) CopyParams added in v0.0.26

func (t *Task) CopyParams()

Reset task for re-use

func (*Task) Diarize added in v0.0.26

func (t *Task) Diarize() bool

Return the diarize flag

func (*Task) Init added in v0.0.26

func (t *Task) Init(path string, model *schema.Model, gpu int, tracer trace.Tracer) error

Init the task

func (*Task) Is added in v0.0.26

func (t *Task) Is(model *schema.Model) bool

Task has a loaded model that matches the argument

func (*Task) Language added in v0.0.26

func (t *Task) Language() string

func (*Task) MarshalJSON added in v0.0.26

func (t *Task) MarshalJSON() ([]byte, error)

func (*Task) Result added in v0.0.26

func (t *Task) Result() *schema.Transcription

Return the transcription result

func (*Task) SetDiarize added in v0.0.26

func (t *Task) SetDiarize(v bool)

Set diarize flag

func (*Task) SetLanguage added in v0.0.26

func (t *Task) SetLanguage(v string) error

Set the language. For transcription, this is the language of the audio samples. For translation, this is the language to translate to. If you set this to "auto" then the language will be detected

func (*Task) SetPrompt added in v0.0.26

func (t *Task) SetPrompt(prompt string) error

Set initial prompt tokens for the transcription

func (*Task) SetTemperature added in v0.0.26

func (t *Task) SetTemperature(v float64) error

Set temperature for sampling

func (*Task) SetTranslate added in v0.0.26

func (t *Task) SetTranslate(v bool)

Set translate to true or false

func (*Task) String added in v0.0.26

func (t *Task) String() string

func (*Task) Transcribe added in v0.0.26

func (t *Task) Transcribe(ctx context.Context, ts time.Duration, samples []float32, fn NewSegmentFunc) error

Transcribe samples. The samples should be 16KHz float32 samples in a single channel. Appends the transcription to the result, and includes segment data if the new segment function is not nil

func (*Task) TranscribeReader added in v0.0.26

func (t *Task) TranscribeReader(ctx context.Context, r io.Reader, fn NewSegmentFunc, segmenterOpts ...segmenter.Opt) error

TranscribeReader transcribes audio from an io.Reader using the segmenter to automatically handle audio decoding and segmentation. This is a higher-level convenience function that wraps Transcribe.

The reader can be any audio format supported by FFmpeg (mp3, wav, etc.). Audio is automatically decoded, resampled to 16kHz, and converted to mono.

Parameters:

  • ctx: Context for cancellation
  • r: Audio source (any format supported by FFmpeg)
  • fn: Optional callback for each segment during transcription
  • segmenterOpts: Optional segmenter options (e.g., segmenter.WithSegmentSize(30*time.Second))

Returns the final transcription result or an error.

func (*Task) Translate added in v0.0.26

func (t *Task) Translate() bool

Return the translate flag

Directories

Path Synopsis
store implements a model store which allows downloading models from a remote server
store implements a model store which allows downloading models from a remote server

Jump to

Keyboard shortcuts

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