Text Processing
Relevant source files
The following files were used as context for generating this wiki page:
Text processing in the Wikispeech server is the stage where raw input text or SSML is transformed into a structured linguistic representation (markup) suitable for speech synthesis. This process involves tokenization, lexicon lookup, and potentially mapping between different phoneme symbol sets. The system is designed to be modular, using a sequence of components defined in configuration files to process text for specific languages.
Sources: wikispeech_server/wikispeech.py:461-468, wikispeech_server/adapters/README.md:13-17
Architecture and Components
The text processing logic is encapsulated within the Textprocessor class, which manages a list of TextprocComponent objects. Each component represents a specific step in the processing pipeline, such as a MaryTTS preprocessing call or a lexicon server lookup.
Textprocessor Class
The Textprocessor is initialized with a configuration dictionary that specifies its name, language, and the components it should load. It acts as a container for the sequence of operations required to turn text into an utterance structure.
Sources: wikispeech_server/textprocessor.py:20-27
TextprocComponent Class
This class represents an individual module in the pipeline. It typically points to a Python module and a specific function ("call") within that module. Components can also include "mappers" to translate phonemes from one symbol set to another.
The diagram above illustrates the relationship between the Textprocessor container and its constituent components.
Sources: wikispeech_server/textprocessor.py:20-71
Data Flow and Processing Pipeline
The text processing flow starts with a request to the /textprocessing/ API endpoint. The server identifies the appropriate Textprocessor for the requested language and executes its components in sequence.
Execution Logic
- First Component: Typically performs tokenization (e.g., via
marytts_preprocor a basictokenisecall). It takes raw text/SSML and returns the initial Utterance (utt) structure. - Subsequent Components: Take the current Utterance structure, modify it (e.g., by adding transcriptions from a lexicon), and return the updated structure.
- Result: A JSON object containing paragraphs, sentences, phrases, and tokens with linguistic metadata.
Sources: wikispeech_server/wikispeech.py:483-535, wikispeech_server/adapters/README.md:17-21
The flow shows how the Utterance structure is iteratively built by successive components.
Sources: wikispeech_server/wikispeech.py:511-535
Key API Endpoints and Options
The text processing functionality is exposed via several endpoints, allowing clients to discover supported languages, available processors, and perform the actual processing.
| Endpoint | Method | Description |
|---|---|---|
/textprocessing/ | GET/POST | Processes input text and returns structured markup. |
/textprocessing/languages | GET | Returns a list of languages supported for text processing. |
/textprocessing/textprocessors | GET | Returns a list of all defined textprocessor configurations. |
/textprocessing/textprocessors/<lang> | GET | Returns defined textprocessors for a specific language. |
Sources: wikispeech_server/wikispeech.py:421-447, wikispeech_server/options.py:53-103
Parameters for /textprocessing/
The parameters for processing requests are defined in options.py.
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | Yes | The text or SSML to be processed. |
lang | string | Yes | ISO 639-1 two-letter language code. |
textprocessor | string | No | Specific textprocessor name (defaults to language default). |
input_type | string | No | "text" or "ssml" (default: "text"). |
output_type | string | No | Format of output (currently only "json"). |
Sources: wikispeech_server/options.py:58-90
External Adapters and Mappers
Wikispeech uses adapters to interface with third-party tools like MaryTTS. A critical part of this is phoneme mapping, which ensures that transcriptions from different sources (like a lexicon) are compatible with the synthesis engine.
MaryTTS Adapter
The marytts_preproc function sends text to a MaryTTS server to obtain initial intonation and phoneme data. It then converts the resulting MaryXML into the internal Wikispeech Utterance structure.
Sources: wikispeech_server/adapters/marytts_adapter.py:65-104
Phoneme Mapping
Mappers translate between symbol sets (e.g., from sv-se_ws-sampa to sv-se_sampa_mary). This is handled by the Mapper client during component execution.
Sources: wikispeech_server/adapters/marytts_adapter.py:461-487, wikispeech_server/textprocessor.py:68-71
This sequence shows the interaction between the server, adapters, and external services during the processing of a single request.
Sources: wikispeech_server/wikispeech.py:511-535, wikispeech_server/adapters/marytts_adapter.py:65-104
Summary
Text processing in Wikispeech is a highly configurable, multi-stage pipeline. By chaining components such as MaryTTS for initial tokenization and external lexicon servers for high-quality transcriptions, the system builds a rich linguistic model. The modular architecture allows developers to add new languages or processing steps simply by implementing new adapter functions and updating the configuration files.
Sources: wikispeech_server/wikispeech.py:511-535, wikispeech_server/adapters/README.md:1-25