Skip to content

API Reference parrot_formdesigner.audio.narration.lexicon

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.audio.narration.lexicon

View source

Per-locale lexicon and transcript normalisation for voice forms (FEAT-649).

Attribute DEFAULT_LOCALE

Class Lexicon

Locale vocabulary used by the option matcher and command classifier.

Fields:

Field Type Default Description
locale str
ordinals dict[str, int]
cardinals dict[str, int]
yes list[str]
no list[str]
all list[str]
none list[str]
conjunctions list[str]
fillers list[str]
commands dict[str, list[str]]
review_confirm list[str]
review_change list[str]
spoken SpokenLexicon

Class SpokenLexicon

Spoken-token tables for typed post-processors (FEAT-653). Keys are pre-folded with _strip_text.

Fields:

Field Type Default Description
units dict[str, int]
tens dict[str, int]
scales dict[str, int]
number_joiners list[str]
decimal_words list[str]
minus_words list[str]
decimal_separator str '.'
digit_aliases dict[str, str]
repeat_words dict[str, int]
plus_words list[str]
email_symbols dict[str, str]
months dict[str, int]
weekdays dict[str, int]
relative_days dict[str, int]
this_words list[str]
next_words list[str]
last_words list[str]
am_words list[str]
pm_words list[str]
noon_words list[str]
midnight_words list[str]
half_words list[str]
date_order Literal['MDY', 'DMY'] 'MDY'

Attribute TEMPLATES_DIR

Function load_lexicon

Return the lexicon for locale (with fallback), every phrase pre-normalised.

load_lexicon(locale: str) -> Lexicon

Parameter Type Default Description
locale str

Returns: Lexicon

Function load_locale_document

Load the first existing <dir>/<locale>/narration.yaml along the fallback chain.

load_locale_document(locale: str, *, templates_dir: Path | None = None) -> tuple[str, dict[str, Any]]

Parameter Type Default Description
locale str Requested locale (e.g. es-MX).
templates_dir Path | None None Override of the templates root (defaults to the packaged one).

Returns: tuple[str, dict[str, Any]] — (resolved_locale, document).

Raises:

  • FileNotFoundError — when even en is missing.

Function locale_chain

Fallback chain: es-MX → es → en (deduplicated, order kept).

Candidates that do not match _LOCALE_RE are dropped — the chain feeds filesystem paths (<templates>/<candidate>/narration.yaml), so this is the path-injection barrier for every consumer. DEFAULT_LOCALE is always present: a malformed locale yields ["en"].

locale_chain(locale: str) -> list[str]

Parameter Type Default Description
locale str

Returns: list[str]

Function locale_document_path

Return the narration.yaml of the locale directory named candidate, or None.

The returned path is assembled exclusively from entries yielded by base.iterdir(): candidate is only ever compared against a directory name, never concatenated into a path. That makes the locale an allowlist lookup against what is actually installed rather than a caller-supplied path component, which is the CWE-22 barrier for every consumer (the _LOCALE_RE shape check in :func:locale_chain stays as a second layer). Directories symlinked outside base are skipped.

locale_document_path(base: Path, candidate: str) -> Path | None

Parameter Type Default Description
base Path Templates root to search (resolved internally).
candidate str Locale tag to match against the directory names under base.

Returns: Path | None — The existing document path, or None when no such locale directory exists or it holds no narration.yaml.

Attribute logger

Function normalize

Normalise a transcript: accent/case/punctuation folding, then drop whole-word fillers.

Multi-word fillers (e.g. por favor) are removed as exact whole-word phrases.

normalize(text: str, lexicon: Lexicon) -> str

Parameter Type Default Description
text str
lexicon Lexicon

Returns: str

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally