Implemented an initial transcript merge stage
This commit is contained in:
@@ -3,11 +3,13 @@ package builtin
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/model"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/pipeline"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/speaker"
|
||||
)
|
||||
|
||||
type noopPreprocessor struct {
|
||||
@@ -42,6 +44,39 @@ func (p noopPreprocessor) Process(ctx context.Context, in pipeline.PreprocessSta
|
||||
}, nil
|
||||
}
|
||||
|
||||
type trimText struct{}
|
||||
|
||||
func (trimText) Name() string {
|
||||
return "trim-text"
|
||||
}
|
||||
|
||||
func (trimText) Requires() pipeline.ModelState {
|
||||
return pipeline.StateCanonical
|
||||
}
|
||||
|
||||
func (trimText) Produces() pipeline.ModelState {
|
||||
return pipeline.StateCanonical
|
||||
}
|
||||
|
||||
func (trimText) Process(ctx context.Context, in pipeline.PreprocessState, cfg config.Config) (pipeline.PreprocessState, []report.Event, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return pipeline.PreprocessState{}, nil, err
|
||||
}
|
||||
if in.State != pipeline.StateCanonical {
|
||||
return pipeline.PreprocessState{}, nil, fmt.Errorf("preprocessing module %q requires state %q but received %q", "trim-text", pipeline.StateCanonical, in.State)
|
||||
}
|
||||
|
||||
for transcriptIndex := range in.Canonical {
|
||||
for segmentIndex := range in.Canonical[transcriptIndex].Segments {
|
||||
in.Canonical[transcriptIndex].Segments[segmentIndex].Text = strings.TrimSpace(in.Canonical[transcriptIndex].Segments[segmentIndex].Text)
|
||||
}
|
||||
}
|
||||
|
||||
return in, []report.Event{
|
||||
report.Info("preprocessing", "trim-text", "trimmed canonical segment text"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type normalizeSpeakers struct{}
|
||||
|
||||
func (normalizeSpeakers) Name() string {
|
||||
@@ -64,11 +99,33 @@ func (normalizeSpeakers) Process(ctx context.Context, in pipeline.PreprocessStat
|
||||
return pipeline.PreprocessState{}, nil, fmt.Errorf("preprocessing module %q requires state %q but received %q", "normalize-speakers", pipeline.StateRaw, in.State)
|
||||
}
|
||||
|
||||
speakers, err := speaker.LoadMap(cfg.SpeakersFile)
|
||||
if err != nil {
|
||||
return pipeline.PreprocessState{}, nil, err
|
||||
}
|
||||
|
||||
canonical := make([]model.CanonicalTranscript, 0, len(in.Raw))
|
||||
for _, raw := range in.Raw {
|
||||
canonicalSpeaker, err := speakers.SpeakerForSource(raw.Source)
|
||||
if err != nil {
|
||||
return pipeline.PreprocessState{}, nil, err
|
||||
}
|
||||
|
||||
segments := make([]model.Segment, 0, len(raw.Segments))
|
||||
for index, rawSegment := range raw.Segments {
|
||||
segments = append(segments, model.Segment{
|
||||
Source: raw.Source,
|
||||
SourceSegmentIndex: index,
|
||||
Speaker: canonicalSpeaker,
|
||||
Start: rawSegment.Start,
|
||||
End: rawSegment.End,
|
||||
Text: rawSegment.Text,
|
||||
})
|
||||
}
|
||||
|
||||
canonical = append(canonical, model.CanonicalTranscript{
|
||||
Source: raw.Source,
|
||||
Segments: nil,
|
||||
Segments: segments,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -77,6 +134,6 @@ func (normalizeSpeakers) Process(ctx context.Context, in pipeline.PreprocessStat
|
||||
Raw: append([]model.RawTranscript(nil), in.Raw...),
|
||||
Canonical: canonical,
|
||||
}, []report.Event{
|
||||
report.Info("preprocessing", "normalize-speakers", "created placeholder canonical transcript(s)"),
|
||||
report.Info("preprocessing", "normalize-speakers", "created canonical transcript(s) from raw input"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user