speaker_helper.eardrum.discover module

Discovery: the words of a text that are not in the lexicon yet, but should be.

Module summary

A lexicon only fixes the words somebody thought of. A document brings new ones every time — a surname, an acronym, a product, an English term in a French sentence — and the first time anyone notices is when the narration says it wrong. This module reads the text first and lists the words at risk, each with the reasons it was picked:

proper

Capitalised, but not because it opens a sentence (“Feynman”, “Grasse”).

acronym

Two or more capitals and no lowercase (“ONU”, “BMAD”, “GPT-4”).

mixed

Mixed case or letters with digits inside one word (“GitHub”, “ChatGPT”, “mp3”).

foreign

espeak-ng itself switches language to read it (“Tailwind”, “Apple”).

Consecutive capitalised words make one phrase (“Van Gogh”, “Deep Blue”): the lexicon matches phrases, and a surname is often only wrong next to its first name. Words the lexicon already covers are left out — they are checked from the lexicon’s side.

Usage example

>>> [w.word for w in discover("Hier, Feynman parlait de l'ONU sur GitHub.", "fr")]
['Feynman', 'ONU', 'GitHub']

Author

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

class speaker_helper.eardrum.discover.Discovered(word, reasons=<factory>, count=0, example='')[source]

Bases: object

A word of the text at risk of being mispronounced.

Parameters:
word

The word or phrase, as first written in the text.

Type:

str

reasons

Why it was picked (proper, acronym, mixed, foreign, heard).

Type:

list of str

count

How many times it occurs.

Type:

int

example

The first sentence it occurs in (for the report).

Type:

str

count: int = 0
example: str = ''
reasons: list[str]
word: str
speaker_helper.eardrum.discover.discover(text, language, *, known=None, foreign=None)[source]

List the words of text likely to be mispronounced.

Parameters:
  • text (str) – The document.

  • language (str) – ISO-639-1 code of the text.

  • known (callable or None) – word -> bool: whether the lexicon already covers the word (those are skipped). None skips nothing.

  • foreign (callable or None) – (words, language) -> set: the words espeak reads as foreign (speaker_helper.eardrum.espeak.foreign_words()). None turns that rule off — handy in tests, and on machines without espeak.

Returns:

In order of first appearance.

Return type:

list of Discovered