Minor updates to overlap detection and segment coalescing logic
This commit is contained in:
@@ -11,16 +11,20 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultInputReader = "json-files"
|
||||
DefaultOutputModules = "json"
|
||||
DefaultPreprocessingModules = "validate-raw,normalize-speakers,trim-text"
|
||||
DefaultPostprocessingModules = "detect-overlaps,resolve-overlaps,backchannel,filler,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"
|
||||
DefaultInputReader = "json-files"
|
||||
DefaultOutputModules = "json"
|
||||
DefaultPreprocessingModules = "validate-raw,normalize-speakers,trim-text"
|
||||
DefaultPostprocessingModules = "detect-overlaps,resolve-overlaps,backchannel,filler,coalesce,detect-overlaps,autocorrect,assign-ids,validate-output"
|
||||
DefaultOverlapWordRunGap = 0.75
|
||||
DefaultWordRunReorderWindow = 0.4
|
||||
DefaultCoalesceGap = 3.0
|
||||
DefaultCoalesceGapValue = "3.0"
|
||||
DefaultBackchannelMaxDuration = 2.0
|
||||
DefaultFillerMaxDuration = 1.25
|
||||
OverlapWordRunGapEnv = "SERIATIM_OVERLAP_WORD_RUN_GAP"
|
||||
WordRunReorderWindowEnv = "SERIATIM_OVERLAP_WORD_RUN_REORDER_WINDOW"
|
||||
BackchannelMaxDurationEnv = "SERIATIM_BACKCHANNEL_MAX_DURATION"
|
||||
FillerMaxDurationEnv = "SERIATIM_FILLER_MAX_DURATION"
|
||||
)
|
||||
|
||||
// MergeOptions captures raw CLI option values before validation.
|
||||
@@ -39,30 +43,34 @@ type MergeOptions struct {
|
||||
|
||||
// Config is the validated runtime configuration for a merge invocation.
|
||||
type Config struct {
|
||||
InputFiles []string
|
||||
OutputFile string
|
||||
ReportFile string
|
||||
SpeakersFile string
|
||||
AutocorrectFile string
|
||||
InputReader string
|
||||
OutputModules []string
|
||||
PreprocessingModules []string
|
||||
PostprocessingModules []string
|
||||
OverlapWordRunGap float64
|
||||
WordRunReorderWindow float64
|
||||
CoalesceGap float64
|
||||
InputFiles []string
|
||||
OutputFile string
|
||||
ReportFile string
|
||||
SpeakersFile string
|
||||
AutocorrectFile string
|
||||
InputReader string
|
||||
OutputModules []string
|
||||
PreprocessingModules []string
|
||||
PostprocessingModules []string
|
||||
OverlapWordRunGap float64
|
||||
WordRunReorderWindow float64
|
||||
CoalesceGap float64
|
||||
BackchannelMaxDuration float64
|
||||
FillerMaxDuration float64
|
||||
}
|
||||
|
||||
// NewMergeConfig validates raw merge options and returns normalized config.
|
||||
func NewMergeConfig(opts MergeOptions) (Config, error) {
|
||||
cfg := Config{
|
||||
InputReader: strings.TrimSpace(opts.InputReader),
|
||||
OutputModules: nil,
|
||||
PreprocessingModules: nil,
|
||||
PostprocessingModules: nil,
|
||||
OverlapWordRunGap: DefaultOverlapWordRunGap,
|
||||
WordRunReorderWindow: DefaultWordRunReorderWindow,
|
||||
CoalesceGap: DefaultCoalesceGap,
|
||||
InputReader: strings.TrimSpace(opts.InputReader),
|
||||
OutputModules: nil,
|
||||
PreprocessingModules: nil,
|
||||
PostprocessingModules: nil,
|
||||
OverlapWordRunGap: DefaultOverlapWordRunGap,
|
||||
WordRunReorderWindow: DefaultWordRunReorderWindow,
|
||||
CoalesceGap: DefaultCoalesceGap,
|
||||
BackchannelMaxDuration: DefaultBackchannelMaxDuration,
|
||||
FillerMaxDuration: DefaultFillerMaxDuration,
|
||||
}
|
||||
|
||||
if cfg.InputReader == "" {
|
||||
@@ -136,6 +144,14 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
cfg.BackchannelMaxDuration, err = parseBackchannelMaxDuration()
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
cfg.FillerMaxDuration, err = parseFillerMaxDuration()
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
@@ -222,6 +238,14 @@ func parseWordRunReorderWindow() (float64, error) {
|
||||
return parsePositiveFloatEnv(WordRunReorderWindowEnv, DefaultWordRunReorderWindow)
|
||||
}
|
||||
|
||||
func parseBackchannelMaxDuration() (float64, error) {
|
||||
return parsePositiveFloatEnv(BackchannelMaxDurationEnv, DefaultBackchannelMaxDuration)
|
||||
}
|
||||
|
||||
func parseFillerMaxDuration() (float64, error) {
|
||||
return parsePositiveFloatEnv(FillerMaxDurationEnv, DefaultFillerMaxDuration)
|
||||
}
|
||||
|
||||
func parseCoalesceGap(value string) (float64, error) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
|
||||
@@ -206,6 +206,102 @@ func TestWordRunReorderWindowRejectsInvalidEnvOverride(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackchannelMaxDurationDefaultsTo2(t *testing.T) {
|
||||
t.Setenv(BackchannelMaxDurationEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
cfg, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.BackchannelMaxDuration != DefaultBackchannelMaxDuration {
|
||||
t.Fatalf("backchannel max duration = %f, want %f", cfg.BackchannelMaxDuration, DefaultBackchannelMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackchannelMaxDurationUsesValidEnvOverride(t *testing.T) {
|
||||
t.Setenv(BackchannelMaxDurationEnv, "1.5")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
cfg, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.BackchannelMaxDuration != 1.5 {
|
||||
t.Fatalf("backchannel max duration = %f, want 1.5", cfg.BackchannelMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackchannelMaxDurationRejectsInvalidEnvOverride(t *testing.T) {
|
||||
assertPositiveFloatEnvValidation(t, BackchannelMaxDurationEnv)
|
||||
}
|
||||
|
||||
func TestFillerMaxDurationDefaultsTo125(t *testing.T) {
|
||||
t.Setenv(FillerMaxDurationEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
cfg, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.FillerMaxDuration != DefaultFillerMaxDuration {
|
||||
t.Fatalf("filler max duration = %f, want %f", cfg.FillerMaxDuration, DefaultFillerMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillerMaxDurationUsesValidEnvOverride(t *testing.T) {
|
||||
t.Setenv(FillerMaxDurationEnv, "1.75")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
cfg, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.FillerMaxDuration != 1.75 {
|
||||
t.Fatalf("filler max duration = %f, want 1.75", cfg.FillerMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillerMaxDurationRejectsInvalidEnvOverride(t *testing.T) {
|
||||
assertPositiveFloatEnvValidation(t, FillerMaxDurationEnv)
|
||||
}
|
||||
|
||||
func TestCoalesceGapDefaultsTo3(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
@@ -306,6 +402,44 @@ func TestCoalesceGapRejectsInvalidOverride(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func assertPositiveFloatEnvValidation(t *testing.T, envName string) {
|
||||
t.Helper()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value string
|
||||
want string
|
||||
}{
|
||||
{name: "non-numeric", value: "fast", want: "must be a positive number"},
|
||||
{name: "zero", value: "0", want: "must be positive"},
|
||||
{name: "negative", value: "-0.1", want: "must be positive"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Setenv(envName, test.value)
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
_, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("expected error to contain %q, got %v", test.want, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func writeTempFile(t *testing.T, dir string, name string) string {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user