speaker_helper.eardrum.loop module
The Ralph Eardrum Loop: say it, hear it, fix the spelling, say it again.
Module summary
For each word under test — a lexicon entry, or a word discovered in a document — the loop:
finds the target pronunciation (
targets: the lexicon’s IPA, Wiktionary, Wikipedia, else espeak);has the real engine say the word inside two carrier sentences (“Je vous parle de … aujourd’hui.”), because a word said alone is not said the way it is said in a sentence;
hears each take with a phoneme recogniser (
ear), finds the word inside the sentence and scores it against the target (phones); the take’s score is the mean over the carriers;when the score is above the threshold, asks the local LLM for another respelling, showing it the target and every earlier attempt with what was heard and how far it was, and goes back to 2 — at most
max_itertimes;keeps the best attempt, not the last one, and records it in the lexicon’s verified sidecar (
lexicon.yaml.eardrum.yaml) for this engine, so every later synthesis uses it.
A hand-written respelling is never replaced: when it fails, the report says so and proposes the better one, and the human decides. For an engine that takes phonemes (kokoro), there is nothing to respell — the loop checks that the target IPA itself comes out right and records it.
Every take is written to disk, and the report (index.html) puts each
word’s clips side by side: the measure points, the ear decides.
Usage example
>>> carriers_for("fr")[0]
"Je vous parle de {w} aujourd'hui."
- class speaker_helper.eardrum.loop.Attempt(candidate, kind, origin, score=1.0, takes=<factory>)[source]
Bases:
objectOne candidate spelling (or IPA) and its takes.
- origin
Where it came from:
"written"(the word as written),"current"(what the lexicon applies today),"llm","target"(the target IPA itself, for phoneme engines).- Type:
- speaker_helper.eardrum.loop.CARRIERS: dict[str, list[str]] = {'de': ['Ich spreche heute über {w} mit euch.', 'Es war {w}, der das sagte.'], 'en': ['I am talking about {w} today.', 'It was {w} who said it.'], 'es': ['Hoy les hablo de {w} otra vez.', 'Fue {w} quien lo dijo.'], 'fr': ["Je vous parle de {w} aujourd'hui.", "C'est bien {w} qui l'a dit."], 'it': ['Oggi vi parlo di {w} di nuovo.', 'È stato {w} a dirlo.'], 'pt': ['Hoje falo de {w} outra vez.', 'Foi {w} quem o disse.']}
Carrier sentences per language. Neutral, short, the word in the middle, with plain words around it that every engine and espeak read alike.
- speaker_helper.eardrum.loop.CLIP_PAD_S = 0.08
Padding around a word’s clip, so its first and last phones are audible.
- speaker_helper.eardrum.loop.DEFAULT_THRESHOLD = 0.25
Below this score a take counts as said right. Calibrated on chatterbox French takes: “Faïnemane” heard as
s a i n m a nagainst /fajnman/ scores 0.06, the wrong “fènman” scores 0.39.
- speaker_helper.eardrum.loop.IMPROVEMENT_MARGIN = 0.05
A new respelling must beat the current one by this much to replace it: two takes of the same text differ by a few hundredths on their own.
- class speaker_helper.eardrum.loop.Listener(speaker, ear, espeak, out_dir)[source]
Bases:
objectSays a candidate through the real engine and scores what is heard.
- Parameters:
- speaker_helper.eardrum.loop.SPELLING_GUIDE: dict[str, str] = {'en': '/ʃ/ sh · /tʃ/ ch · /ʒ/ zh · /dʒ/ j · /k/ k · /ɡ/ g · /ŋ/ ng · /j/ y · /i/ ee · /ɪ/ i · /u/ oo · /ʊ/ u · /y/ ew · /e/ ay · /ɛ/ e · /æ/ a · /ɑ/ ah · /ɔ/ aw · /o/ oh · /ə/ uh · /aɪ/ eye · /aʊ/ ow · /ʁ/ r · stress the syllable written in capitals only if needed.', 'fr': '/ʃ/ ch · /tʃ/ tch · /dʒ/ dj · /ʒ/ j · /k/ k or qu · /ɡ/ g (gu before e, i) · /s/ ss between vowels · /z/ z · /ŋ/ ng · /j/ y or ï · /w/ ou · /h/ (silent, drop it) · /i/ i · /u/ ou · /y/ u · /e/ é · /ɛ/ è · /ə/ e (eu at the end) · /ø/ eu · /o/ ô · /ɔ/ o · /a/ a · /aɪ/ aï · /eɪ/ èï · /aʊ/ aou · /ɔɪ/ oï · /ʌ/ eu · /ɪ/ i · /ʊ/ ou · /θ/ ss · /ð/ d · /ɹ/ r · a final consonant that must be heard gets a final e (Sutton → Seutone), a vowel before n or m that must not be nasal is followed by ne / me (Feynman → Faïnemane).'}
a cheat sheet that turns a small model’s guesswork into lookups. Measured need: without it, gemma3:12b answered “Nitcherche” for /ˈniːtʃə/ three times in a row.
- Type:
How each sound is usually written, per orthography
- class speaker_helper.eardrum.loop.Take(carrier, score, heard, heard_sentence, audio='', clip='')[source]
Bases:
objectOne carrier sentence said with one candidate, and what was heard.
- class speaker_helper.eardrum.loop.WordJob(word, language, entry=None, reasons=<factory>)[source]
Bases:
objectA word to put through the loop.
- Parameters:
word (str)
language (str)
entry (LexiconEntry | None)
- entry
The lexicon entry, when there is one.
- Type:
LexiconEntry or None
- entry: LexiconEntry | None = None
- class speaker_helper.eardrum.loop.WordResult(word, language, engine, reasons=<factory>, source='new', target=None, attempts=<factory>, best=-1, verdict='unresolved', saved=False, note='')[source]
Bases:
objectEverything the loop did for one word.
- Parameters:
- word, language, engine
What was tested, in which language, on which backend.
- Type:
- source
The lexicon entry’s source (
user,builtin,llm,eardrum) or"new"for a discovered word.- Type:
- verdict
ok(already right),fixed(a new spelling passes and was saved),improved(better, saved, still above the threshold),proposal(a hand-written spelling fails; a better one is proposed, not applied),unresolved,no-target.- Type:
- speaker_helper.eardrum.loop.carriers_for(language)[source]
The carrier sentences for
language(English ones as a last resort).
- speaker_helper.eardrum.loop.chosen_variant(variants, intended_ipa)[source]
The accepted pronunciation closest to the one a respelling encodes.
- Parameters:
- Returns:
The closest variant (the first one on a tie).
- Return type:
Examples
>>> chosen_variant(["e.ʃil", "ɛs.kil"], "ɛskil") 'ɛs.kil'
- speaker_helper.eardrum.loop.phones_of(ipa)[source]
Space-separated phones of an IPA string, as shown in reports.
Examples
>>> phones_of("ˈfaɪn.mən") 'f a ɪ n m ə n'
- speaker_helper.eardrum.loop.propose_respelling(word, language, target, history)[source]
Ask the local LLM for a respelling not tried yet.
The model sees the target, a sound-to-spelling guide for the orthography, and every earlier attempt with what the ear heard and, phone by phone, what went wrong — the information a human would use to adjust a spelling by ear. A repeat is answered in the same conversation (“already tried, another one”), with a little more temperature each time.
- Parameters:
- Returns:
A new respelling, or
""when the LLM is unavailable, declines or only repeats earlier attempts.- Return type:
- speaker_helper.eardrum.loop.save_verified(path, key, record)[source]
Write one verified record into the sidecar (read-modify-write).
- speaker_helper.eardrum.loop.slug(word)[source]
A filesystem-safe name for a word.
Examples
>>> slug("Van Gogh"), slug("l'ONU") ('van-gogh', 'l-onu')
- async speaker_helper.eardrum.loop.tune_word(job, listener, resolver, *, engine, max_iter=4, threshold=0.25, llm=True, verified_path=None, current='', proposer=<function propose_respelling>)[source]
Run the loop on one word.
- Parameters:
job (WordJob) – The word.
listener (Listener) – Says and hears candidates.
resolver (TargetResolver) – Finds the target.
engine (str) – Backend name, for the verified key and the report.
max_iter (int) – Maximum number of LLM proposals.
threshold (float) – Score at or below which a take counts as right.
llm (bool) – Allow LLM proposals (off: measure only).
verified_path (Path or None) – Where to save a winning spelling (
None: dry run).current (str) – The respelling applied today for this engine (lexicon, verified sidecar…); empty when the word is read as written.
proposer (callable) – Injected for tests;
propose_respelling()in real use.
- Returns:
Everything tried, the best attempt and the verdict.
- Return type: