Updated the normalize command to correct common errors in WhisperX-generated input transcripts
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
This commit is contained in:
@@ -273,6 +273,66 @@ func TestNormalizeEmptySegmentsArrayProducesValidOutput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRepairsAndDropsDefectiveSegments(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `[
|
||||
{"start": 5, "speaker": "", "text": "keep-a"},
|
||||
{"end": 3, "speaker": " ", "text": "keep-b"},
|
||||
{"speaker": "A"},
|
||||
{"speaker": "A", "text": " "},
|
||||
{"start": 9, "end": 4, "speaker": "B", "text": "keep-c"}
|
||||
]`)
|
||||
output := filepath.Join(dir, "normalized.json")
|
||||
reportPath := filepath.Join(dir, "report.json")
|
||||
|
||||
err := executeNormalize(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--report-file", reportPath,
|
||||
"--output-schema", config.OutputSchemaIntermediate,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("normalize failed: %v", err)
|
||||
}
|
||||
|
||||
var transcript schema.IntermediateTranscript
|
||||
readJSON(t, output, &transcript)
|
||||
if len(transcript.Segments) != 3 {
|
||||
t.Fatalf("segment count = %d, want 3", len(transcript.Segments))
|
||||
}
|
||||
if transcript.Segments[0].Start != 3 || transcript.Segments[0].End != 3 {
|
||||
t.Fatalf("segment[0] timing = %v..%v, want 3..3", transcript.Segments[0].Start, transcript.Segments[0].End)
|
||||
}
|
||||
if transcript.Segments[1].Start != 4 || transcript.Segments[1].End != 9 {
|
||||
t.Fatalf("segment[1] timing = %v..%v, want 4..9", transcript.Segments[1].Start, transcript.Segments[1].End)
|
||||
}
|
||||
if transcript.Segments[2].Start != 5 || transcript.Segments[2].End != 5 {
|
||||
t.Fatalf("segment[2] timing = %v..%v, want 5..5", transcript.Segments[2].Start, transcript.Segments[2].End)
|
||||
}
|
||||
if transcript.Segments[0].Speaker != "Unknown_Speaker" || transcript.Segments[2].Speaker != "Unknown_Speaker" {
|
||||
t.Fatalf("expected Unknown_Speaker placeholders, got %#v", transcript.Segments)
|
||||
}
|
||||
|
||||
var rpt report.Report
|
||||
readJSON(t, reportPath, &rpt)
|
||||
audit := extractNormalizeAudit(t, rpt)
|
||||
if audit.InputSegmentCount != 5 || audit.OutputSegmentCount != 3 {
|
||||
t.Fatalf("audit counts = in:%d out:%d, want in:5 out:3", audit.InputSegmentCount, audit.OutputSegmentCount)
|
||||
}
|
||||
if audit.TimingFieldsRepaired != 2 {
|
||||
t.Fatalf("timing fields repaired = %d, want 2", audit.TimingFieldsRepaired)
|
||||
}
|
||||
if audit.TimingOrderSwapped != 1 {
|
||||
t.Fatalf("timing order swapped = %d, want 1", audit.TimingOrderSwapped)
|
||||
}
|
||||
if audit.SpeakerFilled != 2 {
|
||||
t.Fatalf("speaker filled = %d, want 2", audit.SpeakerFilled)
|
||||
}
|
||||
if audit.SegmentsDroppedText != 2 {
|
||||
t.Fatalf("segments dropped text = %d, want 2", audit.SegmentsDroppedText)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSelectedOutputSchemaIsHonored(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `{"segments":[{"start":1,"end":2,"speaker":"A","text":"one"}]}`)
|
||||
@@ -434,11 +494,16 @@ type normalizeAudit struct {
|
||||
OutputFile string `json:"output_file"`
|
||||
InputShape string `json:"input_shape"`
|
||||
InputSegmentCount int `json:"input_segment_count"`
|
||||
OutputSegmentCount int `json:"output_segment_count"`
|
||||
OutputSchema string `json:"output_schema"`
|
||||
OutputModules []string `json:"output_modules"`
|
||||
IDsReassigned bool `json:"ids_reassigned"`
|
||||
SortingChangedInput bool `json:"sorting_changed_input_order"`
|
||||
SegmentsWithCategories int `json:"segments_with_categories"`
|
||||
TimingFieldsRepaired int `json:"timing_fields_repaired"`
|
||||
TimingOrderSwapped int `json:"timing_order_swapped"`
|
||||
SpeakerFilled int `json:"speaker_filled"`
|
||||
SegmentsDroppedText int `json:"segments_dropped_text"`
|
||||
}
|
||||
|
||||
func extractNormalizeAudit(t *testing.T, rpt report.Report) normalizeAudit {
|
||||
|
||||
Reference in New Issue
Block a user