Files
Summerize/internal/transcribe/segments.go
2026-05-10 13:37:17 -06:00

50 lines
1.1 KiB
Go

package transcribe
import (
"fmt"
"strings"
)
// Segment is one timestamped chunk of a transcript.
type Segment struct {
Start float64 // seconds from start of audio
End float64
Text string
}
// PlainText joins all segments into a single transcript.
func PlainText(segs []Segment) string {
var b strings.Builder
for _, s := range segs {
b.WriteString(strings.TrimSpace(s.Text))
b.WriteByte(' ')
}
return strings.TrimSpace(b.String())
}
// FormatForLLM renders segments as one timestamped line each, suitable for
// feeding to a model that needs to pick a time window.
//
// [mm:ss] [mm:ss] text
func FormatForLLM(segs []Segment) string {
var b strings.Builder
for _, s := range segs {
fmt.Fprintf(&b, "[%s] [%s] %s\n", formatTS(s.Start), formatTS(s.End), strings.TrimSpace(s.Text))
}
return b.String()
}
func formatTS(seconds float64) string {
if seconds < 0 {
seconds = 0
}
total := int(seconds)
h := total / 3600
m := (total % 3600) / 60
s := total % 60
if h > 0 {
return fmt.Sprintf("%02d:%02d:%02d", h, m, s)
}
return fmt.Sprintf("%02d:%02d", m, s)
}