refactor: reorganize monolithic main package into focused packages
Move the executable entry point to `src/cmd/captioneer` and split audio, capture, config, caption, and model logic into separate packages under `src/`. Update README with new build/run commands and a package-overview section.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user