How scheck-k/ste-gan works
1. Repository purpose
- This is a research training codebase for STE-GAN, a speech-to-EMG generation system.
- The repo is centered on two training pipelines: a pretrained EMG encoder and the main GAN-based speech-to-EMG model.
2. Top-level workflow
- The architecture is data-first: raw corpus data is preprocessed into a structured dataset, then used to train the EMG encoder, then used again to train STE-GAN.
- The main outputs are model checkpoints and training artifacts, not a deployed service.
3. Data preparation boundary
- scripts/clean_audio.py cleans raw audio before feature extraction.
- scripts/prep_data_gaddy_and_klein.py converts the Gaddy & Klein corpus into the repo’s internal data/gaddy_complete/{train,valid,test} layout.
- This preprocessing step creates multiple synchronized modalities per utterance: audio, EMG, EMG features, MFCCs, Soft Speech Units, phonemes, and transcriptions.
4. Dataset and batching subsystem
- ste_gan/data/emg_dataset.py and ste_gan/data/loader.py form the data ingestion layer for training.
- ste_gan/data/collate.py handles batching and variable-length sequence assembly.
- A key boundary here is that silent EMG samples are filtered out for training, because the audio is not synchronous with EMG; the training path focuses on normal/voiced utterances.
5. Feature and modality handling
- The repo treats EMG, acoustic features, and linguistic labels as separate modalities.
- ste_gan/utils/audio_utils.py, emg_utils.py, and common.py provide shared data/feature handling.
- The main speech input feature for STE-GAN is Soft Speech Units from the acoustic side, with MFCCs and phonemes also available in the dataset structure.
6. EMG encoder subsystem
- ste_gan/emg_encoder/train.py trains a standalone model that predicts Soft Speech Units from EMG signals.
- ste_gan/models/emg_encoder.py contains the encoder model used for that task.
- ste_gan/losses/emg_encoder_loss.py and ste_gan/emg_encoder/utils.py support the encoder training loop.
- This pretrained encoder is then reused in the main STE-GAN training as an auxiliary supervisory signal.
7. Main STE-GAN model subsystem
- ste_gan/models/generator.py implements the generator that maps speech features to EMG.
- ste_gan/models/discriminator.py implements the adversarial discriminator.
- The generator is designed around the repo’s stated goals: predict EMG at 800 Hz, use Soft Speech Units as speech input, and incorporate learnable session embeddings to account for recording-session variability.
8. Neural building blocks
- ste_gan/layers/conv.py, transformer.py, and average_filter.py provide the reusable network primitives used by the models.
- The presence of both convolutional and transformer components suggests the generator/encoder stack mixes local temporal modeling with longer-range sequence modeling.
9. Loss and optimization structure
- ste_gan/losses/time_domain_loss.py provides the EMG-oriented waveform/time-domain objective.
- ste_gan/losses/emg_encoder_loss.py supports the auxiliary EMG-encoder objective.
- ste_gan/train.py combines multiple losses, including:
- speech-unit loss
- phoneme loss
- multi-time-domain loss
- feature-matching loss
- These losses are weighted via command-line flags and configuration files.
10. Training orchestration
- ste_gan/train.py is the main experiment entrypoint.
- ste_gan/train_utils.py appears to hold shared training loop utilities, checkpointing, and run management.
- The training script supports resuming from checkpoints, debug mode, overriding batch/chunk sizes, and changing the speech feature type.
11. Configuration system
- YAML configs in configs/ define experiment setups:
- configs/data/gaddy_and_klein_corpus.yaml for dataset paths/splits
- configs/emg_encoder/conv_transformer.yaml for the EMG encoder architecture/training
- configs/ste_gan_base_gantts.yaml for the main STE-GAN run
- The architecture is therefore config-driven rather than hardcoded, with scripts resolving the selected data, model, and training parameters at runtime.
12. External dependencies and research integrations
- The repo builds on ideas and code from CarGAN and HiFi-GAN.
- It depends on Soft-VC for extracting Soft Speech Units and for speech synthesis from those units.
- It uses MetricGAN+ to denoise audio during preprocessing.
- The EMG encoder training is adapted from the silent_speech project.
- These are important architectural boundaries because they supply key upstream features and preprocessing steps rather than being implemented locally.
13. Overall architecture diagram takeaway
- A useful diagram would show three layers:
1. Raw corpus + preprocessing → cleaned audio and extracted multimodal dataset
2. EMG encoder training → pretrained encoder checkpoint
3. STE-GAN training → generator/discriminator plus auxiliary encoder-guided losses
- The main data flow is from speech/audio features and session metadata into the generator, and from EMG targets into the loss functions and discriminator during adversarial training.
Main entry points: ste_gan/train.py Train loop · generator.py Generator · emg_encoder/train.py Encoder train · prep_data_gaddy_and_klein.py Prep corpus
Components 26
Preprocessing
Raw corpus cleaning and multimodal dataset preparation.
- Raw audio · Source corpus and recordings before preprocessing.
- Clean audio · Audio denoising and cleanup before feature extraction.
scripts/clean_audio.py - Prep corpus · Builds the internal train/valid/test multimodal dataset layout.
scripts/prep_data_gaddy_and_klein.py - Dataset config · Corpus paths, splits, and dataset settings.
configs/data/gaddy_and_klein_corpus.yaml
Data
Dataset loading, filtering, and batching.
- Multimodal data · Structured utterances with audio, EMG, EMG features, MFCCs, Soft Speech Units, phonemes, and transcripts.
- Loader · Builds training and validation iterators.
ste_gan/data/loader.py - EMG dataset · Dataset access layer with silent-sample filtering for training.
ste_gan/data/emg_dataset.py - Batching · Assembles variable-length sequences into batches.
ste_gan/data/collate.py
EMG encoder
Standalone pretrained encoder pipeline.
- EMG encoder cfg · Architecture and training settings for the encoder model.
configs/emg_encoder/conv_transformer.yaml - Encoder train · Standalone training loop that predicts Soft Speech Units from EMG.
ste_gan/emg_encoder/train.py - Encoder model · Pretrained EMG-to-Soft-Speech-Units encoder.
ste_gan/models/emg_encoder.py - Encoder loss · Objective used to train the EMG encoder.
ste_gan/losses/emg_encoder_loss.py
STE-GAN
Main adversarial speech-to-EMG training pipeline.
- STE-GAN cfg · Main GAN experiment configuration.
configs/ste_gan_base_gantts.yaml - Train loop · Main experiment entrypoint with checkpointing, resuming, and CLI overrides.
ste_gan/train.py - Train utils · Shared run management and orchestration helpers.
ste_gan/train_utils.py - Generator · Maps speech features and session context to EMG at 800 Hz.
ste_gan/models/generator.py - Discriminator · Adversarial discriminator for EMG realism.
ste_gan/models/discriminator.py - STE-GAN losses · Speech-unit, phoneme, multi-time-domain, and feature-matching objectives.
ste_gan/losses/time_domain_loss.py
Shared core
Reusable layers, losses, and utilities used by both training paths.
- Layers · Reusable convolution, transformer, and averaging primitives.
ste_gan/layers/conv.py - Audio utils · Audio and feature handling helpers.
ste_gan/utils/audio_utils.py - EMG utils · EMG feature and signal helpers.
ste_gan/utils/emg_utils.py - Common utils · Shared constants and general helpers.
ste_gan/utils/common.py
Other components
- Soft-VC · Provides Soft Speech Units and related speech-unit workflow.
- MetricGAN+ · Used for audio denoising during preprocessing.
- CarGAN / HiFi-GAN · Upstream GAN ideas and implementation references.
- silent_speech · Reference for the EMG encoder training adaptation.
Connections 32
- Raw audio → Clean audio: clean · Raw audio is denoised and cleaned before downstream processing.
- Clean audio → Prep corpus: prepare · Cleaned audio feeds multimodal corpus preparation.
- Dataset config → Prep corpus: configure · Dataset config selects paths and split layout for preprocessing.
- Prep corpus → Multimodal data: materialize · Preprocessing writes the structured multimodal dataset.
- MetricGAN+ → Clean audio: denoise · External denoising capability informs audio cleanup.
- Soft-VC → Multimodal data: units · Soft Speech Units are one of the prepared modalities.
- Audio utils → Prep corpus: features · Audio feature helpers support preprocessing.
- EMG utils → Prep corpus: signals · EMG helpers support preprocessing and feature extraction.
- Multimodal data → EMG dataset: load · Dataset objects read the prepared multimodal corpus.
- EMG dataset → Batching: batch · Dataset samples are assembled into variable-length batches.
- Batching → Loader: iterate · Collated batches feed the training data loader.
- Multimodal data → Encoder train: train data · Prepared dataset is consumed by the EMG encoder training loop.
- EMG encoder cfg → Encoder train: configure · Encoder config selects model and training parameters.
- Encoder train → Encoder model: build · Training instantiates the EMG encoder model.
- Encoder train → Encoder loss: optimize · Encoder training uses the dedicated encoder loss.
- silent_speech → Encoder train: adapted from · The encoder training approach is adapted from silent_speech.
- STE-GAN cfg → Train loop: configure · Main STE-GAN run is driven by YAML configuration.
- Loader → Train loop: feed · Training batches are provided to the main loop.
- Train utils → Train loop: orchestrate · Run management and checkpoint utilities support training.
- Train loop → Generator: train · Main loop optimizes the generator.
- Train loop → Discriminator: train · Main loop optimizes the discriminator adversarially.
- Train loop → STE-GAN losses: combine · Training aggregates multiple objectives and weighted losses.
- Generator → Layers: uses · Generator relies on reusable neural building blocks.
- Encoder model → Layers: uses · Encoder also reuses the shared layer primitives.
- STE-GAN losses → Encoder model: aux signal · Pretrained encoder provides auxiliary supervisory signal to main training.
- STE-GAN losses → Generator: supervise · Losses constrain generator outputs against EMG targets and speech-side objectives.
- STE-GAN losses → Discriminator: adversarial · Feature matching and discriminator objectives shape GAN training.
- Generator → Audio utils: speech feats · Generator consumes speech-side features and utilities.
- Generator → EMG utils: EMG target · Generator is trained against EMG signal structure.
- Train loop → Common utils: shared · Common constants and helpers are used by training code.
- Soft-VC → Generator: speech units · Soft Speech Units are the primary speech input representation.
- CarGAN / HiFi-GAN → Generator: inspired by · Generator design builds on CarGAN and HiFi-GAN ideas.