Added a module to coalesce adjacent same-speaker segments
This commit is contained in:
@@ -14,9 +14,13 @@ const (
|
||||
DefaultInputReader = "json-files"
|
||||
DefaultOutputModules = "json"
|
||||
DefaultPreprocessingModules = "validate-raw,normalize-speakers,trim-text"
|
||||
DefaultPostprocessingModules = "detect-overlaps,resolve-overlaps,detect-overlaps,autocorrect,assign-ids,validate-output"
|
||||
DefaultPostprocessingModules = "detect-overlaps,resolve-overlaps,coalesce,detect-overlaps,autocorrect,assign-ids,validate-output"
|
||||
DefaultOverlapWordRunGap = 0.75
|
||||
DefaultWordRunReorderWindow = 0.4
|
||||
DefaultCoalesceGap = 3.0
|
||||
DefaultCoalesceGapValue = "3.0"
|
||||
OverlapWordRunGapEnv = "SERIATIM_OVERLAP_WORD_RUN_GAP"
|
||||
WordRunReorderWindowEnv = "SERIATIM_OVERLAP_WORD_RUN_REORDER_WINDOW"
|
||||
)
|
||||
|
||||
// MergeOptions captures raw CLI option values before validation.
|
||||
@@ -30,6 +34,7 @@ type MergeOptions struct {
|
||||
OutputModules string
|
||||
PreprocessingModules string
|
||||
PostprocessingModules string
|
||||
CoalesceGap string
|
||||
}
|
||||
|
||||
// Config is the validated runtime configuration for a merge invocation.
|
||||
@@ -44,6 +49,8 @@ type Config struct {
|
||||
PreprocessingModules []string
|
||||
PostprocessingModules []string
|
||||
OverlapWordRunGap float64
|
||||
WordRunReorderWindow float64
|
||||
CoalesceGap float64
|
||||
}
|
||||
|
||||
// NewMergeConfig validates raw merge options and returns normalized config.
|
||||
@@ -54,6 +61,8 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
|
||||
PreprocessingModules: nil,
|
||||
PostprocessingModules: nil,
|
||||
OverlapWordRunGap: DefaultOverlapWordRunGap,
|
||||
WordRunReorderWindow: DefaultWordRunReorderWindow,
|
||||
CoalesceGap: DefaultCoalesceGap,
|
||||
}
|
||||
|
||||
if cfg.InputReader == "" {
|
||||
@@ -119,6 +128,14 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
cfg.WordRunReorderWindow, err = parseWordRunReorderWindow()
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
cfg.CoalesceGap, err = parseCoalesceGap(opts.CoalesceGap)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
@@ -198,21 +215,45 @@ func requireFile(path string, flag string) error {
|
||||
}
|
||||
|
||||
func parseOverlapWordRunGap() (float64, error) {
|
||||
value := strings.TrimSpace(os.Getenv(OverlapWordRunGapEnv))
|
||||
return parsePositiveFloatEnv(OverlapWordRunGapEnv, DefaultOverlapWordRunGap)
|
||||
}
|
||||
|
||||
func parseWordRunReorderWindow() (float64, error) {
|
||||
return parsePositiveFloatEnv(WordRunReorderWindowEnv, DefaultWordRunReorderWindow)
|
||||
}
|
||||
|
||||
func parseCoalesceGap(value string) (float64, error) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return DefaultOverlapWordRunGap, nil
|
||||
return DefaultCoalesceGap, 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)
|
||||
return 0, fmt.Errorf("--coalesce-gap must be a non-negative number of seconds: %w", err)
|
||||
}
|
||||
if gap <= 0 {
|
||||
return 0, fmt.Errorf("%s must be positive", OverlapWordRunGapEnv)
|
||||
if gap < 0 {
|
||||
return 0, fmt.Errorf("--coalesce-gap must be non-negative")
|
||||
}
|
||||
return gap, nil
|
||||
}
|
||||
|
||||
func parsePositiveFloatEnv(name string, defaultValue float64) (float64, error) {
|
||||
value := strings.TrimSpace(os.Getenv(name))
|
||||
if value == "" {
|
||||
return defaultValue, nil
|
||||
}
|
||||
|
||||
parsed, err := strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("%s must be a positive number of seconds: %w", name, err)
|
||||
}
|
||||
if parsed <= 0 {
|
||||
return 0, fmt.Errorf("%s must be positive", name)
|
||||
}
|
||||
return parsed, nil
|
||||
}
|
||||
|
||||
func contains(values []string, target string) bool {
|
||||
for _, value := range values {
|
||||
if value == target {
|
||||
|
||||
Reference in New Issue
Block a user