Command Line Adapters (eSpeak/Flite)
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Command Line Adapters in the Wikispeech server enable the use of third-party Text-to-Speech (TTS) engines, specifically eSpeak-ng and Flite, by wrapping their command-line interfaces into the project's synthesis pipeline. These adapters act as intermediaries that transform internal Wikispeech utterance structures into engine-specific markup (SSML or phonemic strings), execute the external binaries, and parse the resulting audio and timing data for the server to return to the client.
Sources: wikispeech_server/adapters/README.md:1-5, wikispeech_server/adapters/flite_adapter.py:23-30, wikispeech_server/adapters/espeak_adapter.py:32-48
Architecture and Data Flow
The adapters follow a standardized interface required by the Wikispeech server. Each synthesis adapter must implement a synthesise function that accepts parameters for language, voice configuration, and input data.
General Synthesis Workflow
When a synthesis request is made, the wikispeech.py module identifies the appropriate adapter based on the voice configuration. The adapter then performs the following steps:
- Input Transformation: Converts the internal utterance dictionary into a format the CLI tool understands (e.g., SSML).
- Execution: Runs the external engine (e.g.,
./engines/fliteorespeak-ng) via system calls. - Output Capture: Captures the generated
.wavaudio file and timing/phoneme information. - Parsing: Reads engine-specific timing files (like
.phofor eSpeak or.timingfor Flite) to create a standardized token list with end times.
Sources: wikispeech_server/wikispeech.py:643-662, wikispeech_server/adapters/README.md:23-28, wikispeech_server/adapters/flite_adapter.py:23-45
This diagram illustrates the high-level flow from the main server module through the specific CLI adapters to the final output. Sources: wikispeech_server/wikispeech.py:643-670, wikispeech_server/adapters/flite_adapter.py:23-110, wikispeech_server/adapters/espeak_adapter.py:32-90
Flite Adapter Implementation
The Flite adapter utilizes the flite engine, often located in a local ./engines/ directory. It relies on SSML for input and produces separate timing files to track phoneme durations.
Key Functions and Logic
synthesise(lang, voice, input, hostname): The main entry point. It generates unique filenames usinguuid, writes SSML to a temporary file, and executes Flite with the-psdurflag to get phoneme durations.utt2ssml(utterance): Iterates through paragraphs, sentences, phrases, and tokens to build a string of<phoneme>tags. It uses a internal mapping (map2flite) to convert Wikispeech phonemes to Flite-compatible labels.- Phoneme Mapping: A dictionary
flitemaptranslates Wikispeech/MaryTTS symbols (e.g., "A", "V", "@") to Flite equivalents (e.g., "aa", "ah", "ax").
Sources: wikispeech_server/adapters/flite_adapter.py:23-31, wikispeech_server/adapters/flite_adapter.py:113-150, wikispeech_server/adapters/flite_adapter.py:153-205
Flite CLI Commands
The adapter constructs commands following this pattern:
./engines/flite -voice [VOICE] -psdur -ssml -f [INPUT_FILE] -o [WAV_OUT] > [TIMING_OUT]
Sources: wikispeech_server/adapters/flite_adapter.py:42-45
eSpeak Adapter Implementation
The eSpeak adapter supports both espeak-ng and MBROLA voices. It primarily uses phonemic strings enclosed in double brackets (e.g., [[...]]) rather than full SSML for its primary synthesis calls.
Key Functions and Logic
synthesise(lang, voice, input, hostname): Orchestrates the dual-call process to generate both phoneme timing (via--pho) and the final audio.utt2phonemics(utterance): Converts the utterance tokens into eSpeak phonemic representations using a mapping system.testVoice(config): Validates the availability of a voice by runningespeak-ng -v [VOICE] -q test.
Sources: wikispeech_server/adapters/espeak_adapter.py:5-18, wikispeech_server/adapters/espeak_adapter.py:32-60, wikispeech_server/adapters/espeak_adapter.py:126-150
Timing Parsing in eSpeak
The adapter parses .pho files which contain lines with phoneme symbols and their durations in milliseconds. It calculates cumulative endtime values for tokens.
Sources: wikispeech_server/adapters/espeak_adapter.py:63-88
Configuration and Parameters
Adapters are defined within JSON configuration files and loaded by wikispeech.py.
Adapter Configuration Example
| Field | Description | Source |
|---|---|---|
name | Unique identifier for the voice | voice.py:18 |
lang | ISO 639-1 language code | voice.py:19 |
engine | TTS engine type (e.g., "marytts", "flite") | voice.py:20 |
adapter | Python module path (e.g., "adapters.flite_adapter") | voice.py:21 |
flite_voice | Specific Flite voice name (for Flite adapter) | flite_adapter.py:24 |
espeak_voice | eSpeak voice identifier (for eSpeak adapter) | espeak_adapter.py:34 |
Internal Phoneme Mappings
Both adapters include mapping functions to ensure compatibility between the server's internal phoneme sets (often Sampa-based) and the CLI engine requirements.
# Flite mapping logic example
def map2flite(phonestring):
phonestring = re.sub("' ","1 ", phonestring)
# ... mapping logic ...
return flite
Sources: wikispeech_server/adapters/flite_adapter.py:208-228, wikispeech_server/adapters/espeak_adapter.py:214-232
Summary
The Command Line Adapters provide a flexible way to extend Wikispeech synthesis capabilities without requiring deep integration with TTS engine internals. By standardizing the input/output through synthesise functions and providing robust phoneme mapping and timing parsers, the server can treat diverse CLI-based engines as unified synthesis services.
Sources: wikispeech_server/adapters/README.md:1-12, wikispeech_server/wikispeech.py:643-650