Adaptiven A1-Kurs und statistisches Aussprachetraining integrieren

Direkte DeepSeek- und Mistral-Anbindung mit versionierten Aktionsprofilen,
Budgetreservierung, Tokenabrechnung und administrativen Qualitätsprüfungen
ersetzen die Flowise-Abhängigkeit im regulären Betrieb.

840 geprüfte A1-Aufgaben mit geschützter Testauswertung und konkreten offenen
Arbeitsaufträgen ergänzen den Kurs. Inhalts- und Sprachbewertung bleiben von
Azure-Aussprachewerten getrennt; historische Aufgaben und Antworten bleiben erhalten.

Echte Wort- und Phonemmessungen werden mit Herkunft, Aktualität und Nachweisdichte
gebündelt. Go bestimmt Trainingsziele und Wiederholungen, das Modell formuliert
dazu passende Nachsprechübungen. Profilansicht und Auswahlgründe werden angezeigt.

Validierung: Go-Race-Tests mit lokaler PostgreSQL-Integration, go vet,
Web-Build, Audit aller 840 Aufgaben und drei Browser-Smokes mit lokalen
Modell-/Speech-Fixtures bestanden. Keine Produktionsänderungen oder Live-Aufrufe.
This commit is contained in:
Eugenius Naumenko
2026-11-01 23:23:20 +00:00
parent 83944f791e
commit e274eaab2b
186 changed files with 46676 additions and 257 deletions
+96 -22
View File
@@ -53,19 +53,32 @@ func (s *AzureSpeechService) AssessPronunciation(ctx context.Context, input Pron
return domain.PronunciationResult{}, errors.New("target text is required")
}
if s.cfg.AzureMock || s.cfg.AzureSpeechKey == "" || s.cfg.AzureRegion == "" {
return mockPronunciation(input.TargetText), nil
result := mockPronunciation(input.TargetText)
result.Locale = input.Locale
result.Method = "scripted"
result.MeasurementVersion = "demo-v1"
return result, nil
}
endpoint := fmt.Sprintf("https://%s.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=%s",
s.cfg.AzureRegion, url.QueryEscape(valueOr(input.Locale, "en-US")))
assessmentConfig := map[string]any{
"ReferenceText": input.TargetText,
"GradingSystem": "HundredMark",
"Granularity": "Phoneme",
"Dimension": "Comprehensive",
"EnableMiscue": true,
"PhonemeAlphabet": "IPA",
"ReferenceText": input.TargetText,
"GradingSystem": "HundredMark",
"Granularity": "Phoneme",
"Dimension": "Comprehensive",
"EnableMiscue": true,
}
alphabet := ""
switch valueOr(input.Locale, "en-US") {
case "en-US":
alphabet = "IPA"
case "zh-CN":
alphabet = "SAPI"
}
if alphabet != "" {
assessmentConfig["PhonemeAlphabet"] = alphabet
}
assessmentJSON, _ := json.Marshal(assessmentConfig)
@@ -92,7 +105,12 @@ func (s *AzureSpeechService) AssessPronunciation(ctx context.Context, input Pron
s.logger.Warn("azure pronunciation failed", "status", resp.StatusCode, "body", string(body))
return domain.PronunciationResult{}, fmt.Errorf("azure pronunciation status %d", resp.StatusCode)
}
return parseAzurePronunciation(body)
result, err := parseAzurePronunciation(body)
result.Locale = valueOr(input.Locale, "en-US")
result.Alphabet = alphabet
result.Method = "scripted"
result.MeasurementVersion = "azure-rest-v1"
return result, err
}
func (s *AzureSpeechService) Synthesize(ctx context.Context, locale, voice, text string) ([]byte, string, error) {
@@ -178,12 +196,12 @@ type azurePronunciationResponse struct {
ProsodyScore float64 `json:"ProsodyScore"`
} `json:"PronunciationAssessment"`
Words []struct {
Word string `json:"Word"`
ErrorType string `json:"ErrorType"`
AccuracyScore float64 `json:"AccuracyScore"`
Word string `json:"Word"`
ErrorType string `json:"ErrorType"`
AccuracyScore *float64 `json:"AccuracyScore"`
PronunciationAssessment struct {
AccuracyScore float64 `json:"AccuracyScore"`
ErrorType string `json:"ErrorType"`
AccuracyScore *float64 `json:"AccuracyScore"`
ErrorType string `json:"ErrorType"`
} `json:"PronunciationAssessment"`
Phonemes []struct {
Phoneme string `json:"Phoneme"`
@@ -204,6 +222,9 @@ func parseAzurePronunciation(body []byte) (domain.PronunciationResult, error) {
if len(raw.NBest) == 0 {
return domain.PronunciationResult{}, fmt.Errorf("azure response has no NBest result")
}
if raw.RecognitionStatus != "" && raw.RecognitionStatus != "Success" {
return domain.PronunciationResult{}, fmt.Errorf("Azure recognition did not succeed: %s", raw.RecognitionStatus)
}
best := raw.NBest[0]
result := domain.PronunciationResult{
RecognizedText: firstNonEmpty(best.Display, raw.DisplayText),
@@ -217,7 +238,7 @@ func parseAzurePronunciation(body []byte) (domain.PronunciationResult, error) {
for _, word := range best.Words {
phonemes := make([]string, 0, len(word.Phonemes))
phonemeScores := make([]domain.PhonemeScore, 0, len(word.Phonemes))
for _, phoneme := range word.Phonemes {
for position, phoneme := range word.Phonemes {
if phoneme.Phoneme != "" {
phonemes = append(phonemes, phoneme.Phoneme)
accuracy := phoneme.PronunciationAssessment.AccuracyScore
@@ -226,19 +247,28 @@ func parseAzurePronunciation(body []byte) (domain.PronunciationResult, error) {
}
if accuracy != nil {
phonemeScores = append(phonemeScores, domain.PhonemeScore{
Phoneme: phoneme.Phoneme, Accuracy: *accuracy, Highlight: highlightFor(*accuracy),
Phoneme: phoneme.Phoneme, Accuracy: *accuracy, Highlight: highlightFor(*accuracy), Position: &position,
})
}
}
}
score := firstScore(word.AccuracyScore, word.PronunciationAssessment.AccuracyScore)
measured := word.PronunciationAssessment.AccuracyScore
if measured == nil {
measured = word.AccuracyScore
}
hasScore := measured != nil
score := 0.0
if measured != nil {
score = *measured
}
result.WordScores = append(result.WordScores, domain.WordScore{
Word: word.Word,
Accuracy: score,
ErrorType: firstNonEmpty(word.PronunciationAssessment.ErrorType, word.ErrorType),
Phonemes: phonemes,
PhonemeScores: phonemeScores,
Highlight: highlightFor(score),
Word: word.Word,
AccuracyMeasured: &hasScore,
Accuracy: score,
ErrorType: firstNonEmpty(word.PronunciationAssessment.ErrorType, word.ErrorType),
Phonemes: phonemes,
PhonemeScores: phonemeScores,
Highlight: highlightFor(score),
})
}
return result, nil
@@ -332,3 +362,47 @@ func valueOr(value, fallback string) string {
}
return value
}
// Transcribe is separate from reference-based assessment: free speech must not
// be forced to match an invented model answer. No mock transcript is fabricated.
func (s *AzureSpeechService) Transcribe(ctx context.Context, audio []byte, contentType, locale string) (string, error) {
if s.cfg.AzureMock || s.cfg.AzureSpeechKey == "" || s.cfg.AzureRegion == "" {
return "", errors.New("free speech transcription requires Azure Speech")
}
endpoint := fmt.Sprintf("https://%s.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=%s&format=detailed", s.cfg.AzureRegion, url.QueryEscape(locale))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(audio))
if err != nil {
return "", err
}
req.Header.Set("Ocp-Apim-Subscription-Key", s.cfg.AzureSpeechKey)
req.Header.Set("Content-Type", contentTypeForAzure(contentType))
req.Header.Set("Accept", "application/json")
resp, err := s.client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("Azure transcription HTTP %d", resp.StatusCode)
}
var result struct {
Status string `json:"RecognitionStatus"`
Text string `json:"DisplayText"`
NBest []struct {
Display string `json:"Display"`
} `json:"NBest"`
}
if err = json.NewDecoder(io.LimitReader(resp.Body, 1<<20)).Decode(&result); err != nil {
return "", err
}
if result.Status != "Success" {
return "", errors.New("no speech recognized; please record again")
}
if len(result.NBest) > 0 && result.NBest[0].Display != "" {
return result.NBest[0].Display, nil
}
if strings.TrimSpace(result.Text) == "" {
return "", errors.New("no speech recognized")
}
return result.Text, nil
}