Speech output and Inlandes

Speech output for blind people must be maximally adapted. When a screen reader or a specialized environment like LUWRAIN reads text, raw strings are often insufficient. Text contains abbreviations, ambiguous punctuation, complex numbers, and domain-specific terminology that standard Text-To-Speech (TTS) engines mispronounce. To ensure a seamless and accessible user experience, the text must be preprocessed and expanded into a phonetic or unambiguous form before it reaches the synthesizer.

This is the primary purpose of Inlandes. Inlandes is a specialized text processing language and engine built for the LUWRAIN platform. It provides a robust, rule-based pipeline to transform text using pattern matching, dictionaries, and embedded JavaScript logic.

Core Architecture and Working Principles

The operation of Inlandes can be divided into several distinct phases based on the provided source code:

  1. Tokenization. Before any rules are applied, the raw input string is processed by the Tokenizer. It converts the text into an array of Token objects. The AbstractTokenizer categorizes characters into specific types defined in the Token.Type enum: NUM, LATIN, CYRIL, SPACE, and PUNC. This lexical analysis simplifies subsequent pattern matching, as the engine operates on semantic chunks rather than raw characters.
  2. Rule Parsing. Transformation logic is defined in external .rules files. The SyntaxParser uses ANTLR4 to parse these files into an internal representation consisting of RuleStatement objects. Each RuleStatement contains a WhereStatement (the matching condition) and a list of Operation objects (the actions to perform). Rules can be grouped into stages using the stageNum property, allowing for sequential, multi-pass text refinement.
  3. Pattern Matching. The core of the recognition process is handled by the Matcher and WhereIterator classes. The engine iterates over the array of Token objects and checks them against the criteria defined in a WhereStatement. The matching system is highly expressive and supports:
    • Token Classes: Filtering tokens by type or case (e.g., cyril-cap, char-latin-lower).
    • Dictionaries: Checking if a Token exists in a preloaded dictionary via the dicts map.
    • Lemmatization: Matching words by their base form using the Lang interface.
    • Structural Elements: Using Block and Alternative items to create complex, regex-like logical branches. Items can also be marked as optional.
    • JavaScript Conditions: The JsObj filter allows evaluating a JavaScript expression via the ScriptEngine to determine if a match is valid.
  4. Collision Handling. When multiple rules match overlapping segments of text, Inlandes resolves these conflicts in the handleCollisions method. The engine prioritizes the longest match. If a shorter match overlaps with a longer one, the shorter Matching is discarded.
  5. Execution of Operations.** Once a valid Matching is confirmed, the engine executes the associated Operation objects. There are two main types of operations:
    • Action: Executes arbitrary JavaScript code for side effects.
    • Assignment: Replaces the matched sequence of tokens with a new ReplacementToken. The replacement value can be a static string or the result of a JavaScript expression evaluated by the GraalVmEngine.
  6. JavaScript Integration. To provide maximum flexibility, Inlandes tightly integrates with GraalVM through the GraalVmEngine class, which implements the ScriptEngine interface. During operation execution, the engine creates bindings for the matched token references (e.g., binding the first captured group to the variable _1). This allows rule authors to write complex transformation logic in JavaScript, utilizing the captured text to generate the correct phonetic output.

By combining strict token-based pattern matching with the dynamic power of JavaScript, the Inlandes library acts as a highly adaptable preprocessor. It ensures that text is perfectly formatted for speech synthesizers, ultimately delivering a highly adapted and accessible experience for blind users of the LUWRAIN platform.