Phonembewertung speichern und anzeigen

Azure-Phonemwerte in Versuchen sichern, schwache Laute im Fortschritt und Flowise-Kontext auswerten und die Web-Anzeige ergänzen. README dokumentiert Datenfluss, Betrieb und Grenzen der Funktion.
This commit is contained in:
Eugenius Naumenko
2026-10-10 17:59:44 +00:00
parent bac840e091
commit 82d8768a99
13 changed files with 451 additions and 59 deletions
+42 -5
View File
@@ -54,6 +54,7 @@ func (f *FlowiseTeacher) NextExercise(ctx context.Context, input domain.Generate
ReasonForChoice: "Fallback exercise because Flowise did not return a valid exercise.",
Source: "fallback",
}
progress := compactProgressForFlowise(input.Progress)
payload := map[string]any{
"task": "next_exercise",
"user_id": input.UserID,
@@ -61,16 +62,37 @@ func (f *FlowiseTeacher) NextExercise(ctx context.Context, input domain.Generate
"cefr_level": input.CEFRLevel,
"ui_language": input.UILanguage,
"profile": input.Profile,
"progress": input.Progress,
"recent_weak_words": input.RecentWeakWords,
"progress": progress,
"recent_weak_words": withoutPhonemeScores(input.RecentWeakWords),
"recent_weak_phonemes": input.Progress.WeakPhonemes,
"preferred_type": valueOr(input.PreferredType, "repeat_sentence"),
"avoid_reference_text": input.AvoidReferenceText,
"avoid_reference_texts": input.AvoidReferenceTexts,
"rules": "Generate one A1 English pronunciation exercise. Return valid JSON only with fields: exercise_type, target_language, cefr_level, reference_text, display_prompt, tts_text, focus_points, success_criteria, reason_for_choice. The reference_text must differ from every sentence in avoid_reference_texts. The same target word may still be used.",
"rules": "Generate one A1 English pronunciation exercise. Return valid JSON only with fields: exercise_type, target_language, cefr_level, reference_text, display_prompt, tts_text, focus_points, success_criteria, reason_for_choice. The reference_text must differ from every sentence in avoid_reference_texts. Use recent_weak_phonemes only when measured scores are provided; do not invent pronunciation errors.",
}
return f.askExercise(ctx, payload, input, fallback)
}
func compactProgressForFlowise(progress domain.ProgressSummary) domain.ProgressSummary {
progress.WeakWords = withoutPhonemeScores(progress.WeakWords)
recent := make([]domain.Attempt, len(progress.RecentAttempts))
for i, attempt := range progress.RecentAttempts {
recent[i] = attempt
recent[i].WordScores = withoutPhonemeScores(attempt.WordScores)
}
progress.RecentAttempts = recent
return progress
}
func withoutPhonemeScores(words []domain.WordScore) []domain.WordScore {
clean := make([]domain.WordScore, len(words))
copy(clean, words)
for i := range clean {
clean[i].PhonemeScores = nil
}
return clean
}
func (f *FlowiseTeacher) FeedbackForAttempt(ctx context.Context, targetText string, result domain.PronunciationResult, weakWords []domain.WordScore) (domain.TeacherResponse, error) {
_ = ctx
_ = weakWords
@@ -261,10 +283,22 @@ func parseGeneratedExerciseJSON(value json.RawMessage) (domain.GeneratedExercise
func mockFeedback(targetText string, result domain.PronunciationResult) domain.TeacherResponse {
weakWord := ""
weakPhoneme := domain.PhonemeScore{}
weakPhonemeWord := ""
for _, word := range result.WordScores {
if word.Highlight == "weak" {
weakWord = word.Word
break
if weakWord == "" {
weakWord = word.Word
}
}
if strings.EqualFold(word.ErrorType, "Omission") {
continue
}
for _, phoneme := range word.PhonemeScores {
if phoneme.Accuracy < 75 && (weakPhonemeWord == "" || phoneme.Accuracy < weakPhoneme.Accuracy) {
weakPhoneme = phoneme
weakPhonemeWord = word.Word
}
}
}
feedback := "Der Satz braucht noch etwas Übung. Sprich ihn noch einmal nach."
@@ -273,6 +307,9 @@ func mockFeedback(targetText string, result domain.PronunciationResult) domain.T
case result.OverallScore >= 95 && result.AccuracyScore >= 95 && result.FluencyScore >= 95 && result.CompletenessScore >= 95:
feedback = "Ausgezeichnet gesprochen! Die Aussprache dieses Satzes wurde sehr hoch bewertet."
nextRecommendation = "Du kannst mit einer neuen Übung weitermachen."
case weakPhonemeWord != "":
feedback = fmt.Sprintf("Im Wort %q wurde der Laut /%s/ mit %.0f von 100 Punkten bewertet.", weakPhonemeWord, weakPhoneme.Phoneme, weakPhoneme.Accuracy)
nextRecommendation = fmt.Sprintf("Wiederhole den Satz und achte besonders auf %q.", weakPhonemeWord)
case weakWord != "":
feedback = fmt.Sprintf("Das Wort %q wurde noch unsicher bewertet. Übe es im Satz noch einmal.", weakWord)
nextRecommendation = fmt.Sprintf("Wiederhole den Satz und achte besonders auf %q.", weakWord)