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.
95 lines
3.0 KiB
Go
95 lines
3.0 KiB
Go
package services
|
|
|
|
import "testing"
|
|
|
|
func TestMockPronunciationReturnsWordScores(t *testing.T) {
|
|
result := mockPronunciation("Hello, my name is Anna.")
|
|
|
|
if result.Provider != "mock" {
|
|
t.Fatalf("expected mock provider, got %s", result.Provider)
|
|
}
|
|
if len(result.WordScores) != 5 {
|
|
t.Fatalf("expected 5 word scores, got %d", len(result.WordScores))
|
|
}
|
|
if result.OverallScore <= 0 {
|
|
t.Fatalf("expected positive score, got %f", result.OverallScore)
|
|
}
|
|
}
|
|
|
|
func TestParseAzurePronunciationTopLevelScores(t *testing.T) {
|
|
body := []byte(`{
|
|
"RecognitionStatus": "Success",
|
|
"DisplayText": "Can I have a coffee please?",
|
|
"NBest": [{
|
|
"Display": "Can I have a coffee please?",
|
|
"AccuracyScore": 94.0,
|
|
"FluencyScore": 99.0,
|
|
"CompletenessScore": 100.0,
|
|
"PronScore": 96.2,
|
|
"Words": [{
|
|
"Word": "can",
|
|
"AccuracyScore": 94.0,
|
|
"ErrorType": "None",
|
|
"Phonemes": [{"Phoneme": "k"}, {"Phoneme": "ae"}, {"Phoneme": "n"}]
|
|
}]
|
|
}]
|
|
}`)
|
|
|
|
result, err := parseAzurePronunciation(body)
|
|
if err != nil {
|
|
t.Fatalf("parse azure pronunciation: %v", err)
|
|
}
|
|
if result.Provider != "azure" {
|
|
t.Fatalf("expected azure provider, got %s", result.Provider)
|
|
}
|
|
if result.OverallScore != 96.2 {
|
|
t.Fatalf("expected overall score 96.2, got %f", result.OverallScore)
|
|
}
|
|
if result.AccuracyScore != 94 {
|
|
t.Fatalf("expected accuracy score 94, got %f", result.AccuracyScore)
|
|
}
|
|
if len(result.WordScores) != 1 {
|
|
t.Fatalf("expected one word score, got %d", len(result.WordScores))
|
|
}
|
|
if result.WordScores[0].Accuracy != 94 {
|
|
t.Fatalf("expected word accuracy 94, got %f", result.WordScores[0].Accuracy)
|
|
}
|
|
if result.WordScores[0].Highlight != "good" {
|
|
t.Fatalf("expected good highlight, got %s", result.WordScores[0].Highlight)
|
|
}
|
|
if len(result.WordScores[0].PhonemeScores) != 0 {
|
|
t.Fatalf("unscored phonemes must not become zero-point weaknesses: %#v", result.WordScores[0].PhonemeScores)
|
|
}
|
|
}
|
|
|
|
func TestParseAzurePronunciationKeepsPhonemeScores(t *testing.T) {
|
|
body := []byte(`{
|
|
"NBest": [{"Display":"water","PronScore":82,"Words":[{
|
|
"Word":"water","AccuracyScore":80,
|
|
"Phonemes":[
|
|
{"Phoneme":"w","PronunciationAssessment":{"AccuracyScore":93}},
|
|
{"Phoneme":"ɔ","PronunciationAssessment":{"AccuracyScore":0}},
|
|
{"Phoneme":"t","AccuracyScore":58},
|
|
{"Phoneme":"ə"}
|
|
]
|
|
}]}]
|
|
}`)
|
|
result, err := parseAzurePronunciation(body)
|
|
if err != nil {
|
|
t.Fatalf("parse azure pronunciation: %v", err)
|
|
}
|
|
word := result.WordScores[0]
|
|
if len(word.Phonemes) != 4 || len(word.PhonemeScores) != 3 {
|
|
t.Fatalf("expected four phoneme labels and three scored phonemes, got %#v", word)
|
|
}
|
|
if word.PhonemeScores[0].Accuracy != 93 || word.PhonemeScores[0].Highlight != "good" {
|
|
t.Fatalf("unexpected first phoneme score %#v", word.PhonemeScores[0])
|
|
}
|
|
if word.PhonemeScores[1].Accuracy != 0 || word.PhonemeScores[1].Highlight != "weak" {
|
|
t.Fatalf("zero is a valid low score, got %#v", word.PhonemeScores[1])
|
|
}
|
|
if word.PhonemeScores[2].Accuracy != 58 || word.PhonemeScores[2].Highlight != "weak" {
|
|
t.Fatalf("top-level phoneme score was not read: %#v", word.PhonemeScores[2])
|
|
}
|
|
}
|