Added initial segment overlap resolution logic

This commit is contained in:
2026-04-27 15:52:53 -05:00
parent e42a2326e8
commit 1b9f4bd922
16 changed files with 1357 additions and 59 deletions

View File

@@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
)
@@ -14,6 +15,8 @@ const (
DefaultOutputModules = "json"
DefaultPreprocessingModules = "validate-raw,normalize-speakers,trim-text"
DefaultPostprocessingModules = "detect-overlaps,resolve-overlaps,autocorrect,assign-ids,validate-output"
DefaultOverlapWordRunGap = 0.75
OverlapWordRunGapEnv = "SERIATIM_OVERLAP_WORD_RUN_GAP"
)
// MergeOptions captures raw CLI option values before validation.
@@ -40,6 +43,7 @@ type Config struct {
OutputModules []string
PreprocessingModules []string
PostprocessingModules []string
OverlapWordRunGap float64
}
// NewMergeConfig validates raw merge options and returns normalized config.
@@ -49,6 +53,7 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
OutputModules: nil,
PreprocessingModules: nil,
PostprocessingModules: nil,
OverlapWordRunGap: DefaultOverlapWordRunGap,
}
if cfg.InputReader == "" {
@@ -110,6 +115,11 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
}
}
cfg.OverlapWordRunGap, err = parseOverlapWordRunGap()
if err != nil {
return Config{}, err
}
return cfg, nil
}
@@ -187,6 +197,22 @@ func requireFile(path string, flag string) error {
return nil
}
func parseOverlapWordRunGap() (float64, error) {
value := strings.TrimSpace(os.Getenv(OverlapWordRunGapEnv))
if value == "" {
return DefaultOverlapWordRunGap, nil
}
gap, err := strconv.ParseFloat(value, 64)
if err != nil {
return 0, fmt.Errorf("%s must be a positive number of seconds: %w", OverlapWordRunGapEnv, err)
}
if gap <= 0 {
return 0, fmt.Errorf("%s must be positive", OverlapWordRunGapEnv)
}
return gap, nil
}
func contains(values []string, target string) bool {
for _, value := range values {
if value == target {