Segment Voxtral transcripts for telephony
This commit is contained in:
@@ -75,17 +75,24 @@ func TestVoxtralUsesAudioTranscriptionsEndpoint(t *testing.T) {
|
||||
}))
|
||||
defer audioSrv.Close()
|
||||
|
||||
var gotPath, gotModel string
|
||||
var gotPath, gotModel, gotResponseFormat string
|
||||
providerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotPath = r.URL.Path
|
||||
if err := r.ParseMultipartForm(16 << 20); err != nil {
|
||||
t.Fatalf("ParseMultipartForm: %v", err)
|
||||
}
|
||||
gotModel = r.FormValue("model")
|
||||
gotResponseFormat = r.FormValue("response_format")
|
||||
if _, _, err := r.FormFile("file"); err != nil {
|
||||
t.Fatalf("FormFile: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"text": "Алло, тест."})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"text": "Алло, тест. Да, слышно.",
|
||||
"segments": []map[string]any{
|
||||
{"start": 0, "end": 1.2, "text": "Алло, тест."},
|
||||
{"start": 1.2, "end": 2.4, "text": "Да, слышно."},
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer providerSrv.Close()
|
||||
|
||||
@@ -107,11 +114,27 @@ func TestVoxtralUsesAudioTranscriptionsEndpoint(t *testing.T) {
|
||||
if gotModel != "mistralai/Voxtral-Small-24B-2507" {
|
||||
t.Fatalf("model = %q", gotModel)
|
||||
}
|
||||
if len(got.Segments) != 1 || got.Segments[0].Text != "Алло, тест." {
|
||||
if gotResponseFormat != "verbose_json" {
|
||||
t.Fatalf("response_format = %q, want verbose_json", gotResponseFormat)
|
||||
}
|
||||
if len(got.Segments) != 2 || got.Segments[0].Text != "Алло, тест." || got.Segments[1].Start != 1.2 {
|
||||
t.Fatalf("segments = %#v", got.Segments)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSegmentTranscriptTextAddsHeuristicSpeakers(t *testing.T) {
|
||||
got := segmentTranscriptText("Алло, добрый день. Да, слушаю. Скажите, квартира продается? Да, продается.", true)
|
||||
if len(got) < 2 {
|
||||
t.Fatalf("segments = %#v, want multiple", got)
|
||||
}
|
||||
if got[0].Speaker != "SPEAKER_00" || got[1].Speaker != "SPEAKER_01" {
|
||||
t.Fatalf("speakers = %q/%q", got[0].Speaker, got[1].Speaker)
|
||||
}
|
||||
if got[1].Start <= got[0].Start {
|
||||
t.Fatalf("segment times did not advance: %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func near(got, want float64) bool {
|
||||
return math.Abs(got-want) < 0.000001
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user