admin b5c083e06f
Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
first commit
2026-06-04 18:10:52 +07:00

137 lines
3.4 KiB
Go

package config
import (
"os"
"github.com/urfave/cli/v2"
)
func LoadResolved(path string) (File, error) {
if path == "" {
if _, err := os.Stat("config.yaml"); err == nil {
path = "config.yaml"
} else {
return DefaultFile(), nil
}
}
return LoadFile(path)
}
func mergeVAD(c *cli.Context, v VAD) VAD {
if c.IsSet("vad") {
v.Enabled = c.Bool("vad")
}
if c.IsSet("vad-model") {
v.Model = c.String("vad-model")
}
if c.IsSet("vad-threshold") {
v.Threshold = c.Float64("vad-threshold")
}
if c.IsSet("vad-min-speech-ms") {
v.MinSpeechMs = c.Int("vad-min-speech-ms")
}
if c.IsSet("vad-min-silence-ms") {
v.MinSilenceMs = c.Int("vad-min-silence-ms")
}
if c.IsSet("vad-max-speech-sec") {
v.MaxSpeechSec = c.Float64("vad-max-speech-sec")
}
if c.IsSet("vad-speech-pad-ms") {
v.SpeechPadMs = c.Int("vad-speech-pad-ms")
}
if c.IsSet("vad-samples-overlap") {
v.SamplesOverlap = c.Float64("vad-samples-overlap")
}
return v.WithDefaults()
}
func mergeAPI(c *cli.Context, a API) API {
if c.IsSet("addr") {
a.Addr = c.String("addr")
}
if c.IsSet("models-dir") {
a.ModelsDir = c.String("models-dir")
}
if c.IsSet("cache-dir") {
a.CacheDir = c.String("cache-dir")
}
if c.IsSet("threads") {
a.Threads = c.Uint("threads")
}
if c.IsSet("language") {
a.Language = c.String("language")
}
if c.IsSet("debug") {
a.Debug = c.Bool("debug")
}
if c.IsSet("speedup") {
a.SpeedUp = c.Bool("speedup")
}
if c.IsSet("translate") {
a.Translate = c.Bool("translate")
}
if c.IsSet("prompt") {
a.Prompt = c.String("prompt")
}
if c.IsSet("max-context") {
a.MaxContext = c.Uint("max-context")
}
if c.IsSet("beam-size") {
a.BeamSize = c.Uint("beam-size")
}
if c.IsSet("entropy-thold") {
a.EntropyThold = c.Float64("entropy-thold")
}
a.VAD = mergeVAD(c, a.VAD)
if c.IsSet("default-punctuation") {
a.DefaultPunctuation = c.Bool("default-punctuation")
}
return a
}
func APIFromCLI(c *cli.Context) (API, error) {
file, err := LoadResolved(c.String("config"))
if err != nil {
return API{}, err
}
return mergeAPI(c, file.API), nil
}
func TranscodeFromCLI(c *cli.Context) (Transcode, error) {
file, err := LoadResolved(c.String("config"))
if err != nil {
return Transcode{}, err
}
return file.Transcode.WithDefaults(), nil
}
func mergePunctuation(c *cli.Context, p Punctuation) Punctuation {
if c.IsSet("punctuation-enabled") {
p.Enabled = c.Bool("punctuation-enabled")
}
if c.IsSet("punctuation-engine") {
p.Engine = c.String("punctuation-engine")
}
if c.IsSet("punctuation-default-on") {
p.DefaultOn = c.Bool("punctuation-default-on")
}
return p.WithDefaults()
}
func PunctuationFromCLI(c *cli.Context) (Punctuation, error) {
file, err := LoadResolved(c.String("config"))
if err != nil {
return Punctuation{}, err
}
return mergePunctuation(c, file.Punctuation), nil
}
func DiarizationFromCLI(c *cli.Context) (Diarization, error) {
file, err := LoadResolved(c.String("config"))
if err != nil {
return Diarization{}, err
}
return file.Diarization.WithDefaults(), nil
}