speaker_helper.eardrum package

Submodules

Module contents

The Ralph Eardrum Loop: re-listen to every word, fix how it is spelled for the engine, until the engine says it right.

Module summary

The sibling of the Ralph Eyeball Loop (render a figure, look at it, fix the source): here the engine says a word, a phoneme recogniser hears it, the distance to the right pronunciation is measured, and the respelling the engine is handed is rewritten until the word comes out right. What is checked:

  • every entry of the lexicon for the language (the default);

  • the words of a document at risk of being mispronounced and not in the lexicon yet — proper nouns, acronyms, brand-shaped words, words espeak reads as foreign (discover);

  • optionally (listen_all) every word of the document: each sentence is said with today’s lexicon and heard back, and the words that came out far from their expected reading join the list;

  • or an explicit list of words.

Winning spellings go to lexicon.yaml.eardrum.yaml (per engine, applied on every later synthesis, never over a hand-written one); the report with every take goes to .private/eardrum-loop/<date-time>/index.html.

Submodules: phones (IPA units and distances), targets (what a word should sound like: lexicon, Wiktionary, Wikipedia, espeak), ear (the phoneme recogniser), espeak, discover, loop (one word, start to finish), report.

Usage example

>>> from speaker_helper import Settings
>>> from speaker_helper.eardrum import run_eardrum
>>> # report = run_eardrum(Settings.from_mapping({"language": "fr"}),
>>> #                      text="Hier, Feynman parlait de l'ONU.")
>>> # report.html  -> .private/eardrum-loop/20261117-213000/index.html

Author

Warith HARCHAOUI — https://linkedin.com/in/warith-harchaoui

class speaker_helper.eardrum.EardrumReport(results=<factory>, html=None, verified_path=None, meta=<factory>)[source]

Bases: object

What a run of the loop produced.

Parameters:
results

One per word.

Type:

list of WordResult

html

The HTML report (None when nothing was written).

Type:

Path or None

verified_path

The sidecar the winning spellings went to (None on a dry run).

Type:

Path or None

meta

Engine, language, threshold, date.

Type:

dict

html: Path | None = None
meta: dict[str, Any]
results: list[WordResult]
property unresolved: list[WordResult]

The words still said wrong (unresolved, proposal, no-target).

verified_path: Path | None = None
class speaker_helper.eardrum.WordJob(word, language, entry=None, reasons=<factory>)[source]

Bases: object

A word to put through the loop.

Parameters:
word

The word or phrase.

Type:

str

language

Language it is spoken in.

Type:

str

entry

The lexicon entry, when there is one.

Type:

LexiconEntry or None

reasons

Why it is tested.

Type:

list of str

entry: LexiconEntry | None = None
language: str
reasons: list[str]
word: str
class speaker_helper.eardrum.WordResult(word, language, engine, reasons=<factory>, source='new', target=None, attempts=<factory>, best=-1, verdict='unresolved', saved=False, note='')[source]

Bases: object

Everything the loop did for one word.

Parameters:
word, language, engine

What was tested, in which language, on which backend.

Type:

str

reasons

Why the word was tested (lexicon, proper, acronym…).

Type:

list of str

source

The lexicon entry’s source (user, builtin, llm, eardrum) or "new" for a discovered word.

Type:

str

target

The Target, as a dict.

Type:

dict or None

attempts

In the order tried.

Type:

list of Attempt

best

Index of the best attempt (-1 when nothing was tried).

Type:

int

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:

str

saved

Whether the verified sidecar was written for this word.

Type:

bool

note

A sentence for the human, in French (the report’s language).

Type:

str

attempts: list[Attempt]
best: int = -1
engine: str
language: str
note: str = ''
reasons: list[str]
saved: bool = False
source: str = 'new'
target: dict[str, Any] | None = None
verdict: str = 'unresolved'
word: str
speaker_helper.eardrum.collect_jobs(lexicon, language, *, text=None, words=None, include_lexicon=True, foreign=None)[source]

Decide which words the loop will test.

Parameters:
  • lexicon (Lexicon or None) – The project’s lexicon.

  • language (str) – Language of the text.

  • text (str or None) – A document: its lexicon words and its discovered words are tested.

  • words (list of str or None) – Explicit words (tested whatever else is asked).

  • include_lexicon (bool) – Without text: test every lexicon entry of the language. With text: test the lexicon entries the text contains.

  • foreign (callable or None) – espeak-based foreign-word detection, forwarded to discover().

Returns:

No word twice.

Return type:

list of WordJob

speaker_helper.eardrum.run_eardrum(settings, **kwargs)[source]

Synchronous wrapper around run_eardrum_async().

Parameters:
Returns:

The results and where the report went.

Return type:

EardrumReport

async speaker_helper.eardrum.run_eardrum_async(settings, *, text=None, words=None, include_lexicon=True, listen_everything=False, max_iter=4, threshold=0.25, web=True, llm=True, dry_run=False, out_dir=None, ear=None, speaker=None, resolver=None)[source]

Run the Ralph Eardrum Loop; see the module docstring.

Parameters:
  • settings (Settings) – Engine, language, lexicon location.

  • text (str or None) – A document to check (its lexicon words and discovered words).

  • words (list of str or None) – Explicit words to check.

  • include_lexicon (bool) – Also check lexicon entries (all of them without text).

  • listen_everything (bool) – Say the whole text first and add every word heard far from its expected reading.

  • max_iter (int) – Maximum LLM proposals per word.

  • threshold (float) – Score at or below which a word counts as said right.

  • web (bool) – Look targets up on Wiktionary / Wikipedia.

  • llm (bool) – Let the local LLM propose respellings.

  • dry_run (bool) – Measure and report, but write nothing to the verified sidecar.

  • out_dir (Path or None) – Report directory; a dated folder under DEFAULT_OUT by default.

  • ear (optional) – Injected collaborators (tests); built from settings otherwise.

  • speaker (optional) – Injected collaborators (tests); built from settings otherwise.

  • resolver (optional) – Injected collaborators (tests); built from settings otherwise.

Returns:

The results and where the report went.

Return type:

EardrumReport