Files
claude b954e0cea6 a pronunciation dictionary, so piper stops reading hostnames as noise (V-458)
The RU voice reads a latin word letter by letter or guesses, so 'netdata'
came out as noise and 'homesrv' as nothing. pronounce_ru_v1.json spells the
sound in Cyrillic for the service names, hostnames and acronyms she actually
says, and Speakable applies it last, after the numbers around it are words.

Data, not code: nothing knows any of these names, and adding one is an edit
to the JSON. A word the table does not hold is left exactly as it was, so a
miss is the current behaviour rather than a guess. A malformed file logs and
loads empty, because speech must not stop over a dictionary.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 01:56:11 +04:00

62 lines
1.8 KiB
Go

package ttsnorm
import (
"strings"
"testing"
)
func TestDictionaryLoads(t *testing.T) {
// An empty map is the failure mode, and it is silent at runtime by design.
if len(pronounce) == 0 {
t.Fatal("pronunciation dictionary is empty — it failed to load or failed its version check")
}
}
func TestPronounceRewritesAKnownService(t *testing.T) {
got := Pronounce("netdata говорит что диск заполнен")
if strings.Contains(got, "netdata") {
t.Fatalf("got %q, want the latin name spelled in Cyrillic", got)
}
}
func TestPronounceIsCaseInsensitive(t *testing.T) {
for _, in := range []string{"Netdata", "NETDATA", "netdata"} {
if got := Pronounce(in); got != pronounce["netdata"] {
t.Errorf("Pronounce(%q) = %q, want %q", in, got, pronounce["netdata"])
}
}
}
func TestPronounceLeavesUnknownWordsAlone(t *testing.T) {
// A miss must be the old behaviour, never a guess.
const in = "zzqx упал"
if got := Pronounce(in); got != in {
t.Fatalf("Pronounce(%q) = %q, want it untouched", in, got)
}
}
func TestPronounceDoesNotTouchRussian(t *testing.T) {
const in = "напомню завтра в 19:00"
if got := Pronounce(in); got != in {
t.Fatalf("Pronounce(%q) = %q, want Cyrillic untouched", in, got)
}
}
func TestPronounceMatchesWholeWordsOnly(t *testing.T) {
// "nexuses" is not "nexus", and half-rewriting a word is worse than not
// rewriting it.
if got := Pronounce("nexuses"); got != "nexuses" {
t.Fatalf("Pronounce(\"nexuses\") = %q, want it untouched", got)
}
}
func TestSpeakableAppliesTheDictionary(t *testing.T) {
got := Speakable("homesrv: 10.07.2026")
if strings.Contains(got, "homesrv") {
t.Fatalf("Speakable did not apply the dictionary: %q", got)
}
if !strings.Contains(got, "июля") {
t.Fatalf("Speakable stopped rewriting dates: %q", got)
}
}