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: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	AlignmentAheadsPresetNone         = C.WHISPER_AHEADS_NONE
	AlignmentAheadsPresetNTopMost     = C.WHISPER_AHEADS_N_TOP_MOST
	AlignmentAheadsPresetCustom       = C.WHISPER_AHEADS_CUSTOM
	AlignmentAheadsPresetTinyEn       = C.WHISPER_AHEADS_TINY_EN
	AlignmentAheadsPresetTiny         = C.WHISPER_AHEADS_TINY
	AlignmentAheadsPresetBaseEn       = C.WHISPER_AHEADS_BASE_EN
	AlignmentAheadsPresetBase         = C.WHISPER_AHEADS_BASE
	AlignmentAheadsPresetSmallEn      = C.WHISPER_AHEADS_SMALL_EN
	AlignmentAheadsPresetSmall        = C.WHISPER_AHEADS_SMALL
	AlignmentAheadsPresetMediumEn     = C.WHISPER_AHEADS_MEDIUM_EN
	AlignmentAheadsPresetMedium       = C.WHISPER_AHEADS_MEDIUM
	AlignmentAheadsPresetLargeV1      = C.WHISPER_AHEADS_LARGE_V1
	AlignmentAheadsPresetLargeV2      = C.WHISPER_AHEADS_LARGE_V2
	AlignmentAheadsPresetLargeV3      = C.WHISPER_AHEADS_LARGE_V3
	AlignmentAheadsPresetLargeV3Turbo = C.WHISPER_AHEADS_LARGE_V3_TURBO
)
View Source
const (
	SampleRate = C.WHISPER_SAMPLE_RATE
)

Variables

View Source
var (
	ErrTranscriptionFailed = errors.New("whisper_full failed")
	ErrBadParameter        = errors.New("invalid parameter")
)

Functions

func CleanupAllCallbacks added in v0.0.26

func CleanupAllCallbacks()

CleanupAllCallbacks clears all callbacks from global maps

func NewClient

func NewClient(abspath string) *client

Create a new client with the specified root URL for downloading models

func Whisper_free added in v0.0.9

func Whisper_free(ctx *Context)

Frees all memory allocated by the model.

func Whisper_full added in v0.0.9

func Whisper_full(ctx *Context, params FullParams, samples []float32) error

Run the entire model: PCM -> log mel spectrogram -> encoder -> decoder -> text Not thread safe for same context Uses the specified decoding strategy to obtain the text.

func Whisper_is_multilingual added in v0.0.9

func Whisper_is_multilingual(ctx *Context) bool

Return model capabilities

func Whisper_lang_id added in v0.0.9

func Whisper_lang_id(str string) int

Return the language id of the specified short or full string (e.g. "de" -> 2), or -1 if not found

func Whisper_lang_max_id

func Whisper_lang_max_id() int

Return largest language id (i.e. number of available languages - 1)

func Whisper_lang_str

func Whisper_lang_str(id int) string

Return the short string of the specified language id (e.g. 2 -> "de"), or empty string if not found

func Whisper_lang_str_full added in v0.0.9

func Whisper_lang_str_full(id int) string

Return the long string of the specified language name (e.g. 2 -> "german"), or empty string if not found

func Whisper_log added in v0.0.9

func Whisper_log(level LogLevel, text string, user_data unsafe.Pointer)

Call logging output

func Whisper_log_set

func Whisper_log_set(fn func(level LogLevel, text string))

Set logging output

Types

type AbortCallback added in v0.0.9

type AbortCallback func() bool

If it returns true, the computation is aborted

type AlignmentAheadsPreset added in v0.0.22

type AlignmentAheadsPreset C.enum_whisper_alignment_heads_preset

type Client

type Client interface {
	// Get a file from the server, writing the response to the writer
	// and returning the number of bytes copied
	Get(context.Context, io.Writer, string, ...Opt) (int64, error)
}

The client interface is used to download models

type Context

type Context C.struct_whisper_context

func Whisper_init_from_buffer_with_params added in v0.0.9

func Whisper_init_from_buffer_with_params(data []byte, params ContextParams) *Context

Create a new context with model data and context parameters. Returns nil on error.

func Whisper_init_from_file_with_params added in v0.0.9

func Whisper_init_from_file_with_params(path string, params ContextParams) *Context

Create a new context with path to model and context parameters. Returns nil on error.

func (*Context) DefaultLangId added in v0.0.9

func (ctx *Context) DefaultLangId() int

Language id associated with the context's default state

func (*Context) NumSegments added in v0.0.9

func (ctx *Context) NumSegments() int

Number of generated text segments A segment can be a few words, a sentence, or even a paragraph.

func (*Context) Segment added in v0.0.9

func (ctx *Context) Segment(n int) *Segment

Return a segment, or nil

func (*Context) SegmentNumTokens added in v0.0.9

func (ctx *Context) SegmentNumTokens(n int) int

Get number of tokens in the specified segment

func (*Context) SegmentSpeakerTurnNext added in v0.0.9

func (ctx *Context) SegmentSpeakerTurnNext(n int) bool

Get whether the next segment is predicted as a speaker turn

func (*Context) SegmentT0 added in v0.0.9

func (ctx *Context) SegmentT0(n int) int64

Get the start time of the specified segment

func (*Context) SegmentT1 added in v0.0.9

func (ctx *Context) SegmentT1(n int) int64

Get the end time of the specified segment

func (*Context) SegmentText added in v0.0.9

func (ctx *Context) SegmentText(n int) string

Get the text of the specified segment

func (*Context) SegmentTokenData added in v0.0.9

func (ctx *Context) SegmentTokenData(n, i int) TokenData

Get token data for the specified token in the specified segment This contains probabilities, timestamps, etc.

func (*Context) SegmentTokenId added in v0.0.9

func (ctx *Context) SegmentTokenId(n, i int) int32

Get the token id in the specified segment

func (*Context) SegmentTokenProb added in v0.0.9

func (ctx *Context) SegmentTokenProb(n, i int) float32

Get the token probability of the specified token in the specified segment

func (*Context) SegmentTokenText added in v0.0.9

func (ctx *Context) SegmentTokenText(n, i int) string

Get the token text in the specified segment

func (*Context) Token added in v0.0.9

func (ctx *Context) Token(data TokenData) Token

Return a token from TokenData

func (*Context) Tokens added in v0.0.9

func (ctx *Context) Tokens(n int) []Token

Return tokens for a segment

type ContextParams added in v0.0.9

type ContextParams C.struct_whisper_context_params

func DefaultContextParams added in v0.0.9

func DefaultContextParams() ContextParams

func (*ContextParams) DTWAheadsPreset added in v0.0.22

func (ctx *ContextParams) DTWAheadsPreset() AlignmentAheadsPreset

func (*ContextParams) DTWMemSize added in v0.0.22

func (ctx *ContextParams) DTWMemSize() uintptr

func (*ContextParams) DTWNTop added in v0.0.22

func (ctx *ContextParams) DTWNTop() int

func (*ContextParams) FlashAttn added in v0.0.22

func (ctx *ContextParams) FlashAttn() bool

func (*ContextParams) GpuDevice added in v0.0.22

func (ctx *ContextParams) GpuDevice() int

func (ContextParams) MarshalJSON added in v0.0.9

func (ctx ContextParams) MarshalJSON() ([]byte, error)

func (*ContextParams) SetDTWAheadsPreset added in v0.0.22

func (ctx *ContextParams) SetDTWAheadsPreset(v AlignmentAheadsPreset)

func (*ContextParams) SetDTWMemSize added in v0.0.22

func (ctx *ContextParams) SetDTWMemSize(memSize uintptr)

func (*ContextParams) SetDTWNTop added in v0.0.22

func (ctx *ContextParams) SetDTWNTop(nTop int)

func (*ContextParams) SetFlashAttn added in v0.0.9

func (ctx *ContextParams) SetFlashAttn(v bool)

func (*ContextParams) SetGpuDevice added in v0.0.9

func (ctx *ContextParams) SetGpuDevice(v int)

func (*ContextParams) SetTokenTimestamps added in v0.0.9

func (ctx *ContextParams) SetTokenTimestamps(v bool)

func (*ContextParams) SetUseGpu added in v0.0.9

func (ctx *ContextParams) SetUseGpu(v bool)

func (ContextParams) String added in v0.0.9

func (ctx ContextParams) String() string

func (*ContextParams) TokenTimestamps added in v0.0.22

func (ctx *ContextParams) TokenTimestamps() bool

func (*ContextParams) UseGpu added in v0.0.22

func (ctx *ContextParams) UseGpu() bool

type FullParams added in v0.0.9

type FullParams C.struct_whisper_full_params

func DefaultFullParams added in v0.0.9

func DefaultFullParams(strategy SamplingStrategy) FullParams

Create a new full parameters with the default values for the specified sampling strategy

func (*FullParams) Close added in v0.0.23

func (ctx *FullParams) Close() error

Free all memory allocated by the full parameters

func (*FullParams) Diarize added in v0.0.15

func (c *FullParams) Diarize() bool

func (*FullParams) Language added in v0.0.14

func (c *FullParams) Language() string

func (FullParams) MarshalJSON added in v0.0.9

func (ctx FullParams) MarshalJSON() ([]byte, error)

func (*FullParams) SetAbortCallback added in v0.0.9

func (c *FullParams) SetAbortCallback(ctx *Context, cb AbortCallback)

func (*FullParams) SetDiarize added in v0.0.15

func (c *FullParams) SetDiarize(v bool)

func (*FullParams) SetDurationMS added in v0.0.9

func (c *FullParams) SetDurationMS(v int)

func (*FullParams) SetLanguage added in v0.0.9

func (c *FullParams) SetLanguage(v string)

func (*FullParams) SetMaxTextCtx added in v0.0.9

func (c *FullParams) SetMaxTextCtx(v int)

func (*FullParams) SetNoContext added in v0.0.9

func (c *FullParams) SetNoContext(v bool)

func (*FullParams) SetNoTimestamps added in v0.0.9

func (c *FullParams) SetNoTimestamps(v bool)

func (*FullParams) SetNumThreads added in v0.0.9

func (c *FullParams) SetNumThreads(v int)

func (*FullParams) SetOffsetMS added in v0.0.9

func (c *FullParams) SetOffsetMS(v int)

func (*FullParams) SetPrintProgress added in v0.0.9

func (c *FullParams) SetPrintProgress(v bool)

func (*FullParams) SetPrintRealtime added in v0.0.9

func (c *FullParams) SetPrintRealtime(v bool)

func (*FullParams) SetPrintSpecial added in v0.0.9

func (c *FullParams) SetPrintSpecial(v bool)

func (*FullParams) SetPrintTimestamps added in v0.0.9

func (c *FullParams) SetPrintTimestamps(v bool)

func (*FullParams) SetProgressCallback added in v0.0.9

func (c *FullParams) SetProgressCallback(ctx *Context, cb ProgressCallback)

func (*FullParams) SetPrompt added in v0.0.23

func (c *FullParams) SetPrompt(v string)

func (*FullParams) SetSegmentCallback added in v0.0.9

func (c *FullParams) SetSegmentCallback(ctx *Context, cb SegmentCallback)

func (*FullParams) SetSingleSegment added in v0.0.9

func (c *FullParams) SetSingleSegment(v bool)

func (*FullParams) SetTemperature added in v0.0.23

func (c *FullParams) SetTemperature(v float32)

func (*FullParams) SetTokenTimestamps added in v0.0.9

func (c *FullParams) SetTokenTimestamps(v bool)

func (*FullParams) SetTranslate added in v0.0.9

func (c *FullParams) SetTranslate(v bool)

func (FullParams) String added in v0.0.9

func (ctx FullParams) String() string

func (*FullParams) Temperature added in v0.0.23

func (c *FullParams) Temperature() float32

func (*FullParams) Translate added in v0.0.15

func (c *FullParams) Translate() bool

type HTTPError added in v0.0.9

type HTTPError struct {
	Code    int
	Message string
}

func (*HTTPError) Error added in v0.0.9

func (e *HTTPError) Error() string

type LogLevel

type LogLevel C.enum_ggml_log_level
const (
	LogLevelDebug LogLevel = C.GGML_LOG_LEVEL_DEBUG
	LogLevelInfo  LogLevel = C.GGML_LOG_LEVEL_INFO
	LogLevelWarn  LogLevel = C.GGML_LOG_LEVEL_WARN
	LogLevelError LogLevel = C.GGML_LOG_LEVEL_ERROR
)

func (LogLevel) String

func (v LogLevel) String() string

type Opt added in v0.0.23

type Opt func(*opts) error

Model download options

func WithRemote added in v0.0.23

func WithRemote(remote string) Opt

Set the remote download URL

type ProgressCallback added in v0.0.9

type ProgressCallback func(progress int)

Returns the new segment number

type SamplingStrategy

type SamplingStrategy C.enum_whisper_sampling_strategy
const (
	SAMPLING_GREEDY      SamplingStrategy = C.WHISPER_SAMPLING_GREEDY      // similar to OpenAI's GreedyDecoder
	SAMPLING_BEAM_SEARCH SamplingStrategy = C.WHISPER_SAMPLING_BEAM_SEARCH // similar to OpenAI's BeamSearchDecoder
)

func (SamplingStrategy) MarshalJSON

func (v SamplingStrategy) MarshalJSON() ([]byte, error)

func (SamplingStrategy) String

func (v SamplingStrategy) String() string

type Segment added in v0.0.9

type Segment struct {
	Id          int32         `json:"id"`
	Text        string        `json:"text,omitempty"`
	T0          time.Duration `json:"t0,omitempty"`
	T1          time.Duration `json:"t1,omitempty"`
	SpeakerTurn bool          `json:"speaker_turn,omitempty"`
	Tokens      []Token       `json:"tokens,omitempty"`
}

func (Segment) String added in v0.0.9

func (s Segment) String() string

type SegmentCallback added in v0.0.9

type SegmentCallback func(segment int)

Returns the new segment number

type Token

type Token struct {
	Id   int32         `json:"id"`
	Text string        `json:"text,omitempty"`
	P    float32       `json:"p,omitempty"`
	T0   time.Duration `json:"t0,omitempty"`
	T1   time.Duration `json:"t1,omitempty"`
	Type TokenType     `json:"type,omitempty"`
}

func (Token) String added in v0.0.9

func (t Token) String() string

type TokenData

type TokenData C.struct_whisper_token_data

type TokenType added in v0.0.9

type TokenType int
const (
	EOT  TokenType // end of text
	SOT            // start of transcript
	SOLM           // start of language model
	PREV           // start of previous segment
	NOSP           // no speaker
	NOT            // no timestamps
	BEG            // begin
	LANG           // language (TODO)
)

func (TokenType) MarshalJSON added in v0.0.9

func (t TokenType) MarshalJSON() ([]byte, error)

func (TokenType) String added in v0.0.9

func (t TokenType) String() string

type Writer added in v0.0.9

type Writer interface {
	io.Writer

	// Returns the header of the response. If the return value is
	// not nil, then the Get method will end before the response
	// data is written
	Header(http.Header) error
}

If the writer contains a Header method, it can be used to set the content type and length of the response, to measure progress

Jump to

Keyboard shortcuts

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