Files
Captioneer/src/config/config.go
T

52 lines
1.4 KiB
Go
Raw Normal View History

// Package config defines Captioneer's command-line configuration.
package config
import (
"errors"
"flag"
"time"
)
const DefaultModelsDir = "models"
type Mode string
const (
ModeFixed Mode = "fixed"
ModeVAD Mode = "vad"
)
type Settings struct {
Mode Mode
ChunkDuration time.Duration
ModelsDir string
Threads int
PreviewThresholdDB float64
}
func Parse() Settings {
var settings Settings
mode := ""
flag.StringVar(&mode, "mode", "", "caption mode: vad or fixed (required)")
flag.DurationVar(&settings.ChunkDuration, "chunk-duration", time.Second, "fixed chunk size or VAD preview refresh interval")
flag.StringVar(&settings.ModelsDir, "models-dir", DefaultModelsDir, "directory containing downloaded Sherpa models")
flag.IntVar(&settings.Threads, "threads", 2, "CPU threads used by recognition and VAD")
flag.Float64Var(&settings.PreviewThresholdDB, "preview-threshold-dbfs", -45, "RMS dBFS threshold used to begin VAD previews")
flag.Parse()
settings.Mode = Mode(mode)
return settings
}
func (s Settings) Validate() error {
if s.Mode != ModeFixed && s.Mode != ModeVAD {
return errors.New("--mode is required and must be either fixed or vad")
}
if s.ChunkDuration <= 0 {
return errors.New("--chunk-duration must be positive")
}
if s.Threads <= 0 {
return errors.New("--threads must be positive")
}
return nil
}