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:
- Tokenization. Before any rules are applied, the raw input string is processed by the
Tokenizer. It converts the text into an array ofTokenobjects. TheAbstractTokenizercategorizes characters into specific types defined in theToken.Typeenum:NUM,LATIN,CYRIL,SPACE, andPUNC. This lexical analysis simplifies subsequent pattern matching, as the engine operates on semantic chunks rather than raw characters. - Rule Parsing. Transformation logic is defined in external
.rulesfiles. TheSyntaxParseruses ANTLR4 to parse these files into an internal representation consisting ofRuleStatementobjects. EachRuleStatementcontains aWhereStatement(the matching condition) and a list ofOperationobjects (the actions to perform). Rules can be grouped into stages using thestageNumproperty, allowing for sequential, multi-pass text refinement. - Pattern Matching. The core of the recognition process is handled by the
MatcherandWhereIteratorclasses. The engine iterates over the array ofTokenobjects and checks them against the criteria defined in aWhereStatement. 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
Tokenexists in a preloaded dictionary via thedictsmap. - Lemmatization: Matching words by their base form using the
Langinterface. - Structural Elements: Using
BlockandAlternativeitems to create complex, regex-like logical branches. Items can also be marked as optional. - JavaScript Conditions: The
JsObjfilter allows evaluating a JavaScript expression via theScriptEngineto determine if a match is valid.
- Token Classes: Filtering tokens by type or case (e.g.,
- Collision Handling. When multiple rules match overlapping segments of text, Inlandes resolves these conflicts in the
handleCollisionsmethod. The engine prioritizes the longest match. If a shorter match overlaps with a longer one, the shorterMatchingis discarded. - Execution of Operations.** Once a valid
Matchingis confirmed, the engine executes the associatedOperationobjects. There are two main types of operations:Action: Executes arbitrary JavaScript code for side effects.Assignment: Replaces the matched sequence of tokens with a newReplacementToken. The replacement value can be a static string or the result of a JavaScript expression evaluated by theGraalVmEngine.
- JavaScript Integration. To provide maximum flexibility, Inlandes tightly integrates with GraalVM through the
GraalVmEngineclass, which implements theScriptEngineinterface. 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.