Voice Configuration (JSON)
Relevant source files
The following files were used as context for generating this wiki page:
The Voice Configuration system in Wikispeech-server provides a flexible, file-based mechanism to define how text is processed and synthesized into speech. It allows administrators to specify pipelines involving multiple text processing components and various synthesis engines (like Matcha, Piper, or MaryTTS) through structured JSON files.
This system replaces or supplements hardcoded Python configurations, allowing for dynamic loading of text processors and voices based on settings in the server's main configuration file. Sources: wikispeech_server/wikispeech.py:46-51
System Architecture
The configuration is split into two primary categories: textprocessor_configs and voice_configs. The server loads these from JSON files specified in the global .conf file under the [Voice config] section. Sources: wikispeech_server/wikispeech.py:734-754
Data Flow for Configuration Loading
The following diagram illustrates how the server initializes its voice and text processing capabilities from JSON sources.
Configuration Components
1. Textprocessor Configurations
Text processors define the "Front-end" of the TTS pipeline. They consist of a sequence of components that transform raw text into a structured markup format (typically including tokenization and lexicon lookups).
| Field | Type | Description |
|---|---|---|
name | String | Unique identifier for the text processor. |
lang | String | ISO 639-1 language code (e.g., "sv", "en"). |
default | Boolean | If true, this processor is used when no specific processor is requested. |
components | Array | Ordered list of processing modules to execute. |
Sources: wikispeech_server/conf/voice_config_marytts.json:3-10, wikispeech_server/wikispeech.py:782-793
2. Voice Configurations
Voice configurations define the "Back-end" synthesis engine and the specific voice model to be used.
| Field | Type | Description |
|---|---|---|
name | String | Identifier for the voice model. |
lang | String | Language supported by the voice. |
engine | String | The synthesis engine (e.g., matcha, piper, marytts, flite). |
adapter | String | Python module path for the engine adapter (e.g., adapters.matcha_adapter). |
mapper | Object | (Optional) Defines symbol set mapping for phonemes. |
Sources: wikispeech_server/conf/voice_config_matcha.json:57-64, wikispeech_server/voice.py:17-21
Internal Logic and Classes
The Voice Class
The Voice class (defined in voice.py) encapsulates the configuration for a specific synthesis voice. During initialization, it imports the specified adapter and optionally runs a testVoice method to ensure the underlying synthesis service is reachable.
JSON Comment Stripping
A unique feature of the Wikispeech JSON loader is the ability to handle C-style comments (// or /* ... */) within JSON files, which is not standard in the Python json library. The remove_comments function uses regular expressions to strip these before parsing. Sources: wikispeech_server/wikispeech.py:808-828
Implementation Example: Matcha Voice
The Matcha engine configuration illustrates how complex mappings and adapters are linked.
{
"lang": "sv",
"name": "sv_se_nst_female1",
"engine": "matcha",
"adapter": "adapters.matcha_adapter",
"mapper": {
"from": "sv-se_ws-sampa",
"to": "sv-se_sampa_matcha"
}
}
Sources: wikispeech_server/conf/voice_config_matcha.json:57-65
Validation and Testing
The system includes mechanisms to verify configurations:
- Startup Tests: If
run_startup_testsis enabled in the global configuration, the server attempts to initialize every voice and text processor. Sources: wikispeech_server/wikispeech.py:41-44 - Adapter Verification: Every voice adapter must implement a
testVoice(config)function that verifies the availability of the backend service (e.g., checking if the Matcha or Piper server is running). Sources: wikispeech_server/voice.py:32-37
Summary
The Voice Configuration (JSON) system provides the necessary abstraction layer between the Wikispeech API and various TTS backends. By centralizing text processing pipelines and synthesis engine parameters in JSON files, the project achieves a modular architecture where new languages and voices can be added with minimal changes to the core codebase.