Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupAllCallbacks()
- func NewClient(abspath string) *client
- func Whisper_free(ctx *Context)
- func Whisper_full(ctx *Context, params FullParams, samples []float32) error
- func Whisper_is_multilingual(ctx *Context) bool
- func Whisper_lang_id(str string) int
- func Whisper_lang_max_id() int
- func Whisper_lang_str(id int) string
- func Whisper_lang_str_full(id int) string
- func Whisper_log(level LogLevel, text string, user_data unsafe.Pointer)
- func Whisper_log_set(fn func(level LogLevel, text string))
- type AbortCallback
- type AlignmentAheadsPreset
- type Client
- type Context
- func (ctx *Context) DefaultLangId() int
- func (ctx *Context) NumSegments() int
- func (ctx *Context) Segment(n int) *Segment
- func (ctx *Context) SegmentNumTokens(n int) int
- func (ctx *Context) SegmentSpeakerTurnNext(n int) bool
- func (ctx *Context) SegmentT0(n int) int64
- func (ctx *Context) SegmentT1(n int) int64
- func (ctx *Context) SegmentText(n int) string
- func (ctx *Context) SegmentTokenData(n, i int) TokenData
- func (ctx *Context) SegmentTokenId(n, i int) int32
- func (ctx *Context) SegmentTokenProb(n, i int) float32
- func (ctx *Context) SegmentTokenText(n, i int) string
- func (ctx *Context) Token(data TokenData) Token
- func (ctx *Context) Tokens(n int) []Token
- type ContextParams
- func (ctx *ContextParams) DTWAheadsPreset() AlignmentAheadsPreset
- func (ctx *ContextParams) DTWMemSize() uintptr
- func (ctx *ContextParams) DTWNTop() int
- func (ctx *ContextParams) FlashAttn() bool
- func (ctx *ContextParams) GpuDevice() int
- func (ctx ContextParams) MarshalJSON() ([]byte, error)
- func (ctx *ContextParams) SetDTWAheadsPreset(v AlignmentAheadsPreset)
- func (ctx *ContextParams) SetDTWMemSize(memSize uintptr)
- func (ctx *ContextParams) SetDTWNTop(nTop int)
- func (ctx *ContextParams) SetFlashAttn(v bool)
- func (ctx *ContextParams) SetGpuDevice(v int)
- func (ctx *ContextParams) SetTokenTimestamps(v bool)
- func (ctx *ContextParams) SetUseGpu(v bool)
- func (ctx ContextParams) String() string
- func (ctx *ContextParams) TokenTimestamps() bool
- func (ctx *ContextParams) UseGpu() bool
- type FullParams
- func (ctx *FullParams) Close() error
- func (c *FullParams) Diarize() bool
- func (c *FullParams) Language() string
- func (ctx FullParams) MarshalJSON() ([]byte, error)
- func (c *FullParams) SetAbortCallback(ctx *Context, cb AbortCallback)
- func (c *FullParams) SetDiarize(v bool)
- func (c *FullParams) SetDurationMS(v int)
- func (c *FullParams) SetLanguage(v string)
- func (c *FullParams) SetMaxTextCtx(v int)
- func (c *FullParams) SetNoContext(v bool)
- func (c *FullParams) SetNoTimestamps(v bool)
- func (c *FullParams) SetNumThreads(v int)
- func (c *FullParams) SetOffsetMS(v int)
- func (c *FullParams) SetPrintProgress(v bool)
- func (c *FullParams) SetPrintRealtime(v bool)
- func (c *FullParams) SetPrintSpecial(v bool)
- func (c *FullParams) SetPrintTimestamps(v bool)
- func (c *FullParams) SetProgressCallback(ctx *Context, cb ProgressCallback)
- func (c *FullParams) SetPrompt(v string)
- func (c *FullParams) SetSegmentCallback(ctx *Context, cb SegmentCallback)
- func (c *FullParams) SetSingleSegment(v bool)
- func (c *FullParams) SetTemperature(v float32)
- func (c *FullParams) SetTokenTimestamps(v bool)
- func (c *FullParams) SetTranslate(v bool)
- func (ctx FullParams) String() string
- func (c *FullParams) Temperature() float32
- func (c *FullParams) Translate() bool
- type HTTPError
- type LogLevel
- type Opt
- type ProgressCallback
- type SamplingStrategy
- type Segment
- type SegmentCallback
- type Token
- type TokenData
- type TokenType
- type Writer
Constants ¶
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 )
const (
SampleRate = C.WHISPER_SAMPLE_RATE
)
Variables ¶
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
Return model capabilities
func Whisper_lang_id ¶ added in v0.0.9
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 ¶
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
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
Call logging output
func Whisper_log_set ¶
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
Language id associated with the context's default state
func (*Context) NumSegments ¶ added in v0.0.9
Number of generated text segments A segment can be a few words, a sentence, or even a paragraph.
func (*Context) SegmentNumTokens ¶ added in v0.0.9
Get number of tokens in the specified segment
func (*Context) SegmentSpeakerTurnNext ¶ added in v0.0.9
Get whether the next segment is predicted as a speaker turn
func (*Context) SegmentText ¶ added in v0.0.9
Get the text of the specified segment
func (*Context) SegmentTokenData ¶ added in v0.0.9
Get token data for the specified token in the specified segment This contains probabilities, timestamps, etc.
func (*Context) SegmentTokenId ¶ added in v0.0.9
Get the token id in the specified segment
func (*Context) SegmentTokenProb ¶ added in v0.0.9
Get the token probability of the specified token in the specified segment
func (*Context) SegmentTokenText ¶ added in v0.0.9
Get the token text in the specified 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 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 )
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 SegmentCallback ¶ added in v0.0.9
type SegmentCallback func(segment int)
Returns the new segment number
type Token ¶
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
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