Documentation
¶
Index ¶
- Constants
- func WriteSegmentSrt(w io.Writer, seg *schema.Segment)
- func WriteSegmentText(w io.Writer, seg *schema.Segment)
- func WriteSegmentVtt(w io.Writer, seg *schema.Segment)
- type LogFn
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) DeleteModelById(id string) error
- func (m *Manager) DownloadModel(ctx context.Context, path string, fn func(curBytes, totalBytes uint64)) (*schema.Model, error)
- func (m *Manager) GetModelById(id string) *schema.Model
- func (m *Manager) ListModels() []*schema.Model
- func (m *Manager) WithModel(model *schema.Model, fn func(task *Task) error, opts ...Opt) error
- type NewSegmentFunc
- type Opt
- type Task
- func (t *Task) CanTranslate() bool
- func (t *Task) Close() error
- func (t *Task) CopyParams()
- func (t *Task) Diarize() bool
- func (t *Task) Init(path string, model *schema.Model, gpu int, tracer trace.Tracer) error
- func (t *Task) Is(model *schema.Model) bool
- func (t *Task) Language() string
- func (t *Task) MarshalJSON() ([]byte, error)
- func (t *Task) Result() *schema.Transcription
- func (t *Task) SetDiarize(v bool)
- func (t *Task) SetLanguage(v string) error
- func (t *Task) SetPrompt(prompt string) error
- func (t *Task) SetTemperature(v float64) error
- func (t *Task) SetTranslate(v bool)
- func (t *Task) String() string
- func (t *Task) Transcribe(ctx context.Context, ts time.Duration, samples []float32, fn NewSegmentFunc) error
- func (t *Task) TranscribeReader(ctx context.Context, r io.Reader, fn NewSegmentFunc, ...) error
- func (t *Task) Translate() bool
Constants ¶
const ( // Sample Rate SampleRate = whisper.SampleRate )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Manager ¶ added in v0.0.26
Manager provides a global whisper manager with automatic cleanup
func New ¶
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
Close closes the whisper manager and releases all resources. It is safe to call multiple times.
func (*Manager) DeleteModelById ¶ added in v0.0.26
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
GetModelById returns a model by its Id, returns nil if the model does not exist
func (*Manager) ListModels ¶ added in v0.0.26
ListModels returns all models in the models directory
type NewSegmentFunc ¶ added in v0.0.26
Callback for new segments during the transcription process
type Opt ¶ added in v0.0.9
type Opt func(*opts) error
func OptMaxConcurrent ¶ added in v0.0.9
Set maximum number of concurrent tasks
type Task ¶ added in v0.0.26
Task is used for running the transcription or translation
func (*Task) CanTranslate ¶ added in v0.0.26
Model is multilingual and can translate
func (*Task) Close ¶ added in v0.0.26
Close the task and release all resources. The task itself can be re-used by calling Init again
func (*Task) MarshalJSON ¶ added in v0.0.26
func (*Task) Result ¶ added in v0.0.26
func (t *Task) Result() *schema.Transcription
Return the transcription result
func (*Task) SetLanguage ¶ added in v0.0.26
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) SetTemperature ¶ added in v0.0.26
Set temperature for sampling
func (*Task) SetTranslate ¶ added in v0.0.26
Set translate to true or false
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.