2022-12-20 06:54:33 +00:00
|
|
|
package whisper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// TYPES
|
|
|
|
|
|
|
|
// SegmentCallback is the callback function for processing segments in real
|
|
|
|
// time. It is called during the Process function
|
|
|
|
type SegmentCallback func(Segment)
|
|
|
|
|
2023-06-25 11:07:55 +00:00
|
|
|
// ProgressCallback is the callback function for reporting progress during
|
|
|
|
// processing. It is called during the Process function
|
|
|
|
type ProgressCallback func(int)
|
|
|
|
|
2022-12-20 06:54:33 +00:00
|
|
|
// Model is the interface to a whisper model. Create a new model with the
|
|
|
|
// function whisper.New(string)
|
|
|
|
type Model interface {
|
|
|
|
io.Closer
|
|
|
|
|
|
|
|
// Return a new speech-to-text context.
|
|
|
|
NewContext() (Context, error)
|
|
|
|
|
2023-01-07 19:21:43 +00:00
|
|
|
// Return true if the model is multilingual.
|
|
|
|
IsMultilingual() bool
|
|
|
|
|
2022-12-20 06:54:33 +00:00
|
|
|
// Return all languages supported.
|
|
|
|
Languages() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Context is the speach recognition context.
|
|
|
|
type Context interface {
|
2023-02-04 07:09:27 +00:00
|
|
|
SetLanguage(string) error // Set the language to use for speech recognition, use "auto" for auto detect language.
|
2023-01-07 19:21:43 +00:00
|
|
|
SetTranslate(bool) // Set translate flag
|
|
|
|
IsMultilingual() bool // Return true if the model is multilingual.
|
2022-12-20 06:54:33 +00:00
|
|
|
Language() string // Get language
|
2023-01-07 19:21:43 +00:00
|
|
|
|
2024-01-12 11:44:50 +00:00
|
|
|
SetOffset(time.Duration) // Set offset
|
|
|
|
SetDuration(time.Duration) // Set duration
|
|
|
|
SetThreads(uint) // Set number of threads to use
|
|
|
|
SetSplitOnWord(bool) // Set split on word flag
|
|
|
|
SetTokenThreshold(float32) // Set timestamp token probability threshold
|
|
|
|
SetTokenSumThreshold(float32) // Set timestamp token sum probability threshold
|
|
|
|
SetMaxSegmentLength(uint) // Set max segment length in characters
|
|
|
|
SetTokenTimestamps(bool) // Set token timestamps flag
|
|
|
|
SetMaxTokensPerSegment(uint) // Set max tokens per segment (0 = no limit)
|
|
|
|
SetAudioCtx(uint) // Set audio encoder context
|
2024-08-28 14:09:01 +00:00
|
|
|
SetMaxContext(n int) // Set maximum number of text context tokens to store
|
|
|
|
SetBeamSize(n int) // Set Beam Size
|
|
|
|
SetEntropyThold(t float32) // Set Entropy threshold
|
2024-01-12 11:44:50 +00:00
|
|
|
SetInitialPrompt(prompt string) // Set initial prompt
|
2022-12-20 06:54:33 +00:00
|
|
|
|
|
|
|
// Process mono audio data and return any errors.
|
|
|
|
// If defined, newly generated segments are passed to the
|
|
|
|
// callback function during processing.
|
2023-06-25 11:07:55 +00:00
|
|
|
Process([]float32, SegmentCallback, ProgressCallback) error
|
2022-12-20 06:54:33 +00:00
|
|
|
|
|
|
|
// After process is called, return segments until the end of the stream
|
|
|
|
// is reached, when io.EOF is returned.
|
|
|
|
NextSegment() (Segment, error)
|
2023-01-07 19:21:43 +00:00
|
|
|
|
|
|
|
IsBEG(Token) bool // Test for "begin" token
|
|
|
|
IsSOT(Token) bool // Test for "start of transcription" token
|
|
|
|
IsEOT(Token) bool // Test for "end of transcription" token
|
|
|
|
IsPREV(Token) bool // Test for "start of prev" token
|
|
|
|
IsSOLM(Token) bool // Test for "start of lm" token
|
|
|
|
IsNOT(Token) bool // Test for "No timestamps" token
|
|
|
|
IsLANG(Token, string) bool // Test for token associated with a specific language
|
|
|
|
IsText(Token) bool // Test for text token
|
2023-01-25 16:57:30 +00:00
|
|
|
|
2023-01-28 16:44:56 +00:00
|
|
|
// Timings
|
2023-01-25 16:57:30 +00:00
|
|
|
PrintTimings()
|
|
|
|
ResetTimings()
|
2023-01-28 16:44:56 +00:00
|
|
|
|
|
|
|
SystemInfo() string
|
2022-12-20 06:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Segment is the text result of a speech recognition.
|
|
|
|
type Segment struct {
|
|
|
|
// Segment Number
|
|
|
|
Num int
|
|
|
|
|
|
|
|
// Time beginning and end timestamps for the segment.
|
|
|
|
Start, End time.Duration
|
|
|
|
|
|
|
|
// The text of the segment.
|
|
|
|
Text string
|
|
|
|
|
|
|
|
// The tokens of the segment.
|
|
|
|
Tokens []Token
|
|
|
|
}
|
|
|
|
|
|
|
|
// Token is a text or special token
|
|
|
|
type Token struct {
|
2023-04-14 15:52:10 +00:00
|
|
|
Id int
|
|
|
|
Text string
|
|
|
|
P float32
|
|
|
|
Start, End time.Duration
|
2022-12-20 06:54:33 +00:00
|
|
|
}
|